Created
September 1, 2010 09:35
-
-
Save mhenrixon/560465 to your computer and use it in GitHub Desktop.
This file contains 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
public static string OpenSslVerify(string publicKeyFile, string signedContent) | |
{ | |
var pkey = new PublicKey(); | |
pkey.LoadOpenSslPemFile(publicKeyFile); | |
string pkeyXml = pkey.GetXml(); | |
var rsa = new Rsa(); | |
bool success = rsa.UnlockComponent("30-day trial"); | |
if (success != true) | |
{ | |
return ""; | |
} | |
// Import the private key into the RSA component: | |
success = rsa.ImportPublicKey(pkeyXml); | |
if (success != true) | |
{ | |
Console.WriteLine(rsa.LastErrorText); | |
return ""; | |
} | |
// OpenSSL uses BigEndian byte ordering: | |
rsa.LittleEndian = true; | |
// The resulting signature will be a Base64 string: | |
//rsa.EncodingMode = "base64"; | |
//rsa.EncodingMode = "hex"; | |
string realString = rsa.OpenSslVerifyString(Convert.FromBase64String(signedContent)); | |
Console.WriteLine(rsa.LastErrorText); | |
Console.WriteLine(realString); | |
return realString; | |
} |
This file contains 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
public static string OpenSslVerify(string publicKeyFile, string signedContent) | |
{ | |
var pkey = new PublicKey(); | |
pkey.LoadOpenSslPemFile(publicKeyFile); | |
string pkeyXml = pkey.GetXml(); | |
var rsa = new Rsa(); | |
bool success = rsa.UnlockComponent("30-day trial"); | |
if (success != true) | |
{ | |
return ""; | |
} | |
// Import the private key into the RSA component: | |
success = rsa.ImportPublicKey(pkeyXml); | |
if (success != true) | |
{ | |
Console.WriteLine(rsa.LastErrorText); | |
return ""; | |
} | |
// OpenSSL uses BigEndian byte ordering: | |
rsa.LittleEndian = true; | |
// The resulting signature will be a Base64 string: | |
//rsa.EncodingMode = "base64"; | |
//rsa.EncodingMode = "hex"; | |
string realString = rsa.OpenSslVerifyString(Convert.FromBase64String(signedContent).Reverse().ToArray()); | |
Console.WriteLine(rsa.LastErrorText); | |
Console.WriteLine(realString); | |
return realString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment