예제 #1
0
        public static string Encrypt(string key, string data)
        {
            string result = "";

            byte[] keyBytes  = Encoding.UTF8.GetBytes(key);
            byte[] dataBytes = Encoding.UTF8.GetBytes(data);

            List <byte> aesKeyBytes   = new List <byte>();
            List <byte> aesValueBytes = new List <byte>();

            using (SHA256 sha256 = new SHA256CryptoServiceProvider())
            {
                aesKeyBytes = sha256.ComputeHash(keyBytes).ToList();
            }

            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                aesValueBytes = md5.ComputeHash(keyBytes).ToList();
            }

            try
            {
                byte[] resultBytes = Encrypt(aesKeyBytes.ToArray(), aesValueBytes.ToArray(), dataBytes);
                result = ConvertHelper.BytesToHexString(resultBytes);
            }
            catch (Exception exception)
            {
                DevUtility.Com.Application.Log.LogHelper.Error(exception);
            }

            return(result);
        }
예제 #2
0
 public void ByteArrayTest()
 {
     byte[] testBytes = { 0, 1, 2, 3, 1, 2, 3, 1, 2, 1 };
     Assert.AreEqual(testBytes, ConvertHelper.HexStringToBytes(ConvertHelper.BytesToHexString(testBytes)));
     Assert.AreEqual(testBytes, ConvertHelper.StringToBytes(ConvertHelper.BytesToString(testBytes)));
 }