OpenSSL Symmetric Key
[OpenSSL Home][Home]
This page uses the OpenSSL library through a C#/.NET wrapper [1]. The DLLs it interfaces to are libeay32.dll and ssleay32.dll. OpenSSL supports a wide range of encryption methods, including 128-bit AES, 192-bit AES, 256-bit AES and Blowfish (bf). Different modes of ECB, CBC, and OFB are implemented. The examples use a default IV of "1234".
|
Code Used
[HttpPost] public ActionResult openssl(FormCollection form) { ViewData["encrypted"] = "Problem with encryption"; ViewData["encryptedhex"] = "Problem with encryption"; string enc = form["enc"]; string message = form["message"]; string inkey = form["key"]; try { byte[] key = System.Text.Encoding.ASCII.GetBytes(inkey); byte[] input = System.Text.Encoding.ASCII.GetBytes(message); byte[] iv = System.Text.Encoding.ASCII.GetBytes("1234"); OpenSSL.Crypto.Cipher c = getCipher(enc); OpenSSL.Crypto.CipherContext cc = new OpenSSL.Crypto.CipherContext(c); byte[] encrypted = cc.Crypt(input, key, iv, true); byte[] decrypted = cc.Decrypt(encrypted, key, iv); ViewData["key"] = inkey; ViewData["message"] = message; ViewData["encrypted"] = Convert.ToBase64String(encrypted); ViewData["encryptedhex"] = ByteArrayToHexString(encrypted); ViewData["decrypted"] = ByteArrayToString(decrypted); } catch (Exception ex) { ViewData["encrypted"] = ex.Message; ViewData["encryptedhex"] = ex.InnerException; } return PartialView("PartialBlow"); }
Presentation (ECB v CBC)
Reference
[1] The wrapper used is [here].