-
-
Save dukz/7cc5121f04371bb4d9ee 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 Encrypt(string input, string key) | |
{ | |
byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input); | |
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); | |
tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); | |
tripleDES.Mode = CipherMode.ECB; | |
tripleDES.Padding = PaddingMode.PKCS7; | |
ICryptoTransform cTransform = tripleDES.CreateEncryptor(); | |
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); | |
tripleDES.Clear(); | |
return Convert.ToBase64String(resultArray, 0, resultArray.Length); | |
} | |
public static string Decrypt(string input, string key) | |
{ | |
byte[] inputArray = Convert.FromBase64String(input); | |
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); | |
tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); | |
tripleDES.Mode = CipherMode.ECB; | |
tripleDES.Padding = PaddingMode.PKCS7; | |
ICryptoTransform cTransform = tripleDES.CreateDecryptor(); | |
byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); | |
tripleDES.Clear(); | |
return UTF8Encoding.UTF8.GetString(resultArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried doing this, but I'm always getting a "OpenSSL::Cipher::CipherError: key length too short" error.