public SymmetricEncryptionResult Encrypt(SymmetricEncryptionArguments arguments)
 {
     var res = new SymmetricEncryptionResult();
     try
     {
         var rijndael = CreateCipher(arguments);
         res.InitialisationVector = Convert.ToBase64String(rijndael.IV);
         ICryptoTransform cryptoTransform = rijndael.CreateEncryptor();
         byte[] plain = Encoding.UTF8.GetBytes(arguments.PlainText);
         byte[] cipherText = cryptoTransform.TransformFinalBlock(plain, 0, plain.Length);
         res.CipherText = Convert.ToBase64String(cipherText);
         res.Success = true;
     }
     catch (Exception ex)
     {
         res.ExceptionMessage = ex.Message;
     }
     return res;
 }
Ejemplo n.º 2
0
        public SymmetricEncryptionResult Encrypt(SymmetricEncryptionArguments arguments)
        {
            var res = new SymmetricEncryptionResult();

            try
            {
                var rijndael = CreateCipher(arguments);
                res.InitialisationVector = Convert.ToBase64String(rijndael.IV);
                ICryptoTransform cryptoTransform = rijndael.CreateEncryptor();
                byte[]           plain           = Encoding.UTF8.GetBytes(arguments.PlainText);
                byte[]           cipherText      = cryptoTransform.TransformFinalBlock(plain, 0, plain.Length);
                res.CipherText = Convert.ToBase64String(cipherText);
                res.Success    = true;
            }
            catch (Exception ex)
            {
                res.ExceptionMessage = ex.Message;
            }
            return(res);
        }