Ejemplo n.º 1
0
        public void Encrypt256()
        {
            var plaintext     = Encoding.UTF8.GetBytes(Plaintext);
            var etmCiphertext = RijndaelEtM.Encrypt(plaintext, Password, Iv, KeySize.Aes256);

            Assert.Equal(Convert.ToBase64String(etmCiphertext), EtmProof256);
        }
Ejemplo n.º 2
0
        public void RandomIv192()
        {
            var etmCiphertext1 = RijndaelEtM.Encrypt(Plaintext, Password, KeySize.Aes192);
            var etmCiphertext2 = RijndaelEtM.Encrypt(Plaintext, Password, KeySize.Aes192);
            var plaintext      = RijndaelEtM.Decrypt(etmCiphertext1, Password, KeySize.Aes192);

            Assert.Equal(plaintext, Plaintext);
            Assert.NotEqual(etmCiphertext1, etmCiphertext2);
        }
        public static string Encrypt(string plainText, string passPhrase)
        {
            string encrypted = RijndaelEtM.Encrypt(plainText, passPhrase, KeySize.Aes256);

            return(encrypted);

            /**
             * var saltStringBytes = Generate256BitsOfRandomEntropy();
             * var ivStringBytes = Generate256BitsOfRandomEntropy();
             * var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
             * using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
             * {
             *  var keyBytes = password.GetBytes(Keysize / 8);
             *  using (var symmetricKey = new  RijndaelManaged())
             *  {
             *      symmetricKey.BlockSize = 256;
             *      symmetricKey.Mode = CipherMode.CBC;
             *      symmetricKey.Padding = PaddingMode.PKCS7;
             *      using (var encrypter = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes))
             *      {
             *          using (var memoryStream = new MemoryStream())
             *          {
             *              using (var cryptoStream = new CryptoStream(memoryStream, encrypter, CryptoStreamMode.Write))
             *              {
             *                  cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
             *                  cryptoStream.FlushFinalBlock();
             *                  // Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
             *                  var cipherTextBytes = saltStringBytes;
             *                  cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();
             *                  cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray();
             *                  memoryStream.Close();
             *                  cryptoStream.Close();
             *                  return Convert.ToBase64String(cipherTextBytes);
             *              }
             *          }
             *      }
             *  }
             * }**/
        }
Ejemplo n.º 4
0
 public static string Encrypt(string plainText, string password)
 {
     return(RijndaelEtM.Encrypt(plainText, password, KeySize.Aes256));
 }
Ejemplo n.º 5
0
        public static string Encrypt(string plainText, string passPhrase)
        {
            string encrypted = RijndaelEtM.Encrypt(plainText, passPhrase, KeySize.Aes256);

            return(encrypted);
        }