OpenSSL Private Key ExampleThis page uses the OpenSSL library, which supports a wide range of encryption methods. The examples include 128-bit AES, 192-bit AES, 256-bit AES, Blowfish (bf), and so on. Different methods of ECB, CBC, and so on 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"); }