ProtectedKey ProtectKey(byte[] decryptedKey, DataProtectionScope protectionScope) { ProtectedKey key = ProtectedKey.CreateFromPlaintextKey(decryptedKey, protectionScope); CryptographyUtility.ZeroOutBytes(decryptedKey); return(key); }
ProtectedKey GenerateKey(KeyedHashAlgorithm algorithm, DataProtectionScope dataProtectionScope) { using (algorithm) { return(ProtectedKey.CreateFromPlaintextKey(algorithm.Key, dataProtectionScope)); } }
ProtectedKey GenerateKey(SymmetricAlgorithm algorithm, DataProtectionScope dataProtectionScope) { ProtectedKey key; byte[] plaintextKey = this.GenerateUnprotectedKey(algorithm); try { key = ProtectedKey.CreateFromPlaintextKey(plaintextKey, dataProtectionScope); } finally { if (plaintextKey != null) { CryptographyUtility.ZeroOutBytes(plaintextKey); } } return(key); }