Skip to content

Instantly share code, notes, and snippets.

@mhenrixon
Created September 1, 2010 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhenrixon/560465 to your computer and use it in GitHub Desktop.
Save mhenrixon/560465 to your computer and use it in GitHub Desktop.
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;
}
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