Mysql Aes_Decrypt 쿼리 == C# Decrypt String(HEX)
Mysql Aes_Decrypt 쿼리
select cast(AES_DECRYPT(unhex('암호텍스트'),'비밀번호') as char(100)) from log_member;
----------------------------------------------------------------------------------------------------
C# Decrypt String
public static string Decrypt(string _decryptString, string _passkey)
{
RijndaelManaged Rdael = new RijndaelManaged();
Rdael.Mode = CipherMode.CBC;
Rdael.Padding = PaddingMode.PKCS7;
Rdael.KeySize = 128;
Rdael.BlockSize = 128;
// unhex
byte[] bytes = new byte[_decryptString.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = byte.Parse(_decryptString.Substring(i * 2, 2), NumberStyles.HexNumber);
}
byte[] encryptedData = bytes;
byte[] pwdBytes = Encoding.UTF8.GetBytes(_passkey);
byte[] keyBytes = new byte[16];
int len = pwdBytes.Length;
if (len > keyBytes.Length)
{
len = keyBytes.Length;
}
Array.Copy(pwdBytes, keyBytes, len);
Rdael.Key = keyBytes;
Rdael.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] plainText = Rdael.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length);
return Encoding.UTF8.GetString(plainText);
}
참고)
16진수 문자열과 숫자 형식 간 변환 방법 - C# 프로그래밍 가이드 | Microsoft Docs
byte[] array = { 0x64, 0x6f, 0x74, 0x63, 0x65, 0x74 }; string hexValue = Convert.ToHexString(array); Console.WriteLine(hexValue);
[암호화] Java AES128 암호화 복호화 하는법 (tistory.com)
이준빈은 호박머리 (tistory.com)[암호화] Java AES128 암호화 복호화 하는법 (tistory.com)
[C#] 문자열 암/복호화 (AES) – Kim Kitty .NET
C# AES 암호화 / 복호화 예제 소스 코드 (tistory.com)
How to UNHEX() MySQL binary string in C# .NET? - Stack Overflow