Created
February 27, 2017 12:43
-
-
Save tobiasviehweger/3f9f6fbe6c169be09a3d0b0879878c3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Creating file hash + signature with OpenSSL: | |
openssl dgst -sha256 -binary <infile> > <infile>.hash | |
openssl rsautl -sign -inkey somekey.pfx -keyform pkcs12 -passin pass:<password> -in <infile>.hash > <infile>.sig | |
rm <infile>.hash | |
Validating the signature from C#, using both <infile> and <infile>.sig | |
var cert = new X509Certificate2( .. somesource .. ); | |
var csp = (RSACryptoServiceProvider) cert.PublicKey.Key; | |
var sha = new SHA256Managed(); | |
var hash = sha.ComputeHash(File.Open(<infile>, FileMode.Open)); | |
var signature = File.ReadAllBytes(<infile>.sig); | |
bool isValid = csp.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA256"), signature); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment