C# AES 256 암호화 복호화 방법

0 투표
C# AES 256 암호화 복호화 방법 알려주세요.

1 답변

0 투표
#region 암호화 & 복호화

        private string AESEncrypt256(string _text)

        {

            string Password = "https://www.nanumtip.com/"; // 인증키

            RijndaelManaged RijndaelCipher = new RijndaelManaged();

            byte[] PlainText = Encoding.Unicode.GetBytes(_text);

            byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());

            PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);

            ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));

            MemoryStream memoryStream = new MemoryStream();

            CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);

            cryptoStream.Write(PlainText, 0, PlainText.Length);

            cryptoStream.FlushFinalBlock();

            byte[] CipherBytes = memoryStream.ToArray();

            memoryStream.Close();

            cryptoStream.Close();

            return Convert.ToBase64String(CipherBytes);

        }

        private string AESDecrypte256(string _text)

        {

            string Password = "https://www.nanumtip.com/"; // 인증키

            RijndaelManaged RijndaelCipher = new RijndaelManaged();

            byte[] EncryptedData = Convert.FromBase64String(_text);

            byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());

            PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);

            ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));

            MemoryStream memoryStream = new MemoryStream(EncryptedData);

            CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);

            byte[] PlainText = new byte[EncryptedData.Length];

            int DecrypedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);

            memoryStream.Close();

            cryptoStream.Close();

 

            return Encoding.Unicode.GetString(PlainText, 0, DecrypedCount);

        }

        #endregion
구로역 맛집 시흥동 맛집
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
add
...