Mysql
IF pi_actiontype = 'E' THEN SET PO_STR := TO_BASE64(AES_ENCRYPT(pi_str, v_SecKey)); ELSEIF pi_actiontype = 'D' THEN SET PO_STR := AES_DECRYPT(FROM_BASE64(pi_str),v_SecKey);
C#
public static class AESCipherMysql
{
public static String AES_encrypt(String Input, string key)
{
RijndaelManaged aes = new RijndaelManaged();
aes.KeySize = 128;
aes.BlockSize = 128;
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
aes.Key = Encoding.UTF8.GetBytes(key);
aes.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var encrypt = aes.CreateEncryptor(aes.Key, aes.IV);
byte[] xBuff = null;
using (var ms = new MemoryStream())
{
using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write))
{
byte[] xXml = Encoding.UTF8.GetBytes(Input);
cs.Write(xXml, 0, xXml.Length);
cs.FlushFinalBlock();
}
xBuff = ms.ToArray();
}
String output = Convert.ToBase64String(xBuff);
return output;
}
public static String AES_decrypt(String Input, string key)
{
RijndaelManaged aes = new RijndaelManaged();
aes.KeySize = 128;
aes.BlockSize = 128;
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
aes.Key = Encoding.UTF8.GetBytes(key);
aes.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var decrypt = aes.CreateDecryptor();
byte[] encryptedStr = Convert.FromBase64String(Input);
byte[] xBuff = new byte[encryptedStr.Length];
using (var ms = new MemoryStream(encryptedStr))
{
using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Read))
{
cs.Read(xBuff, 0, xBuff.Length);
}
}
String output = Encoding.UTF8.GetString(xBuff);
return output;
}
}
'Develop' 카테고리의 다른 글
| javascript file loading (0) | 2016.07.25 |
|---|---|
| Bootstrap less 404 (0) | 2016.06.28 |
| powershell web 관련 명령어 (0) | 2016.06.02 |
| powershell 폴더구조 복사 (0) | 2016.06.02 |
| powershell 'c:\program files' (0) | 2016.06.02 |