Пример #1
0
 public static string Decrypt(string base64Key, SensitiveValue encrypted)
 {
     using (var encryptor = GetEncrypt())
     {
         encryptor.Key = Convert.FromBase64String(base64Key);
         encryptor.IV  = encrypted.CopyVector();
         using (var enc = encryptor.CreateDecryptor())
         {
             var data = enc.TransformFinalBlock(encrypted.Data, 0, encrypted.Data.Length);
             return(Encoding.UTF8.GetString(data));
         }
     }
 }
Пример #2
0
        public static SensitiveValue Encrypt(string base64Key, string rawData)
        {
            var result   = new SensitiveValue();
            var rawBytes = Encoding.UTF8.GetBytes(rawData);

            using (var encryptor = GetEncrypt())
            {
                encryptor.Key = Convert.FromBase64String(base64Key);
                result.AllocateVector(encryptor.IV);

                using (var enc = encryptor.CreateEncryptor())
                {
                    result.Data = enc.TransformFinalBlock(rawBytes, 0, rawBytes.Length);
                }
            }

            return(result);
        }