private byte[] EncryptKeyForArchival(byte[] keyToExport, string passphrase, byte[] salt) { RijndaelManaged archivalEncryptionAlgorithm = new RijndaelManaged(); byte[] archivalKey = GenerateArchivalKey(archivalEncryptionAlgorithm, passphrase, salt); byte[] iv = new byte[archivalEncryptionAlgorithm.BlockSize / 8]; byte[] encryptedKey = CryptographyUtility.Transform(archivalEncryptionAlgorithm.CreateEncryptor(archivalKey, iv), keyToExport); return(encryptedKey); }
private byte[] DecryptKeyForRestore(string passphrase, byte[] encryptedKey, byte[] salt) { RijndaelManaged archivalEncryptionAlgorithm = new RijndaelManaged(); byte[] restoreKey = GenerateArchivalKey(archivalEncryptionAlgorithm, passphrase, salt); byte[] iv = new byte[archivalEncryptionAlgorithm.BlockSize / 8]; byte[] key = CryptographyUtility.Transform(archivalEncryptionAlgorithm.CreateDecryptor(restoreKey, iv), encryptedKey); CryptographyUtility.ZeroOutBytes(restoreKey); return(key); }
private static byte[] Transform(ICryptoTransform transform, byte[] buffer) { return(CryptographyUtility.Transform(transform, buffer)); }