// TODO: Exception handling /// <summary> /// Fills <c>EncryptionInfo</c> structure and prepares vault /// for encryption. /// </summary> public void SetupEncryption(SecureString password) { if (null == password) { throw new ArgumentNullException("password"); } EncryptionInfo.Salt = CryptoUtilities.RandomBytes(16); EncryptionInfo.IV = CryptoUtilities.RandomBytes(16); EncryptionInfo.ValidationKey = CryptoUtilities.GetValidationKey(password, EncryptionInfo.Salt); EncryptionInfo.ProtectedKey = CryptoUtilities.GetEncryptionProtectionKey(password, EncryptionInfo.Salt); // Protecting encryption key using chosen encryption algorythm using (var cu = new CryptoUtilities(EncryptionInfo.SelectedAlgorithm)) { EncryptionInfo.EncryptionKey = cu.ProtectEncryptionKey(password, CryptoUtilities.RandomBytes(16), EncryptionInfo.Salt, EncryptionInfo.IV); } }
/// <summary> /// Unlike <c>SetupEncryption</c> this method prepares only /// the <c>ProtectedKey</c> property of the vault. /// </summary> public void SetupProtectedKey(SecureString password) { EncryptionInfo.ProtectedKey = CryptoUtilities.GetEncryptionProtectionKey(password, EncryptionInfo.Salt); }