/// <summary> /// <para>Encrypts bytes with the initialized algorithm and key.</para> /// </summary> /// <param name="plaintext"><para>The plaintext in which you wish to encrypt.</para></param> /// <returns><para>The resulting ciphertext.</para></returns> /// <remarks> /// <para>If no encryption is defined, the bytes passed in are returned.</para> /// </remarks> public byte[] Encrypt(byte[] plaintext) { if (encrypted) { SymmetricCryptographer crypt = new SymmetricCryptographer(keyAlgorithmPair.AlgorithmTypeName, keyAlgorithmPair.Key); return crypt.Encrypt(plaintext); } return plaintext; }
private string EncryptKey(byte[] key, string passphrase) { byte[] output = null; byte[] passphraseBytes = GetPassphraseBytes(passphrase); using (SymmetricAlgorithm algorithm = RijndaelManaged.Create()) { SymmetricCryptographer crypto = new SymmetricCryptographer(algorithm, passphraseBytes); byte[] encryptedKey = crypto.Encrypt(key); output = AppendPasswordHash(encryptedKey, passphraseBytes, PasswordProtectedFlag); } return Convert.ToBase64String(output); }