Language: C#
Crypt class using Chilkat
public class Crypt { public static string OpenSslSign(string privateKeyFile, string content) { var pkey = new PrivateKey(); pkey.LoadPemFile(privateKeyFile); 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.ImportPrivateKey(pkeyXml); if (success != true) { Console.WriteLine(rsa.LastErrorText); return ""; } // OpenSSL uses BigEndian byte ordering: rsa.LittleEndian = false; // The resulting signature will be a Base64 string: rsa.EncodingMode = "base64"; string base64Sig = rsa.OpenSslSignStringENC("This is the text to be signed."); Console.WriteLine(base64Sig); return base64Sig; } public static string OpenSslVerify(string publicKeyFile, string signedContent) { var pkey = new PublicKey(); pkey.LoadOpenSslPemFile(publicKeyFile); string pkeyXml = pkey.GetXml(); var rsa = new Rsa { VerboseLogging = true, }; 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 = false; // The resulting signature will be a Base64 string: //rsa.EncodingMode = "base64"; string realString = rsa.OpenSslVerifyStringENC(signedContent); Console.WriteLine(realString); return realString; } }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

