public bool VerifyHmac() { using (Stream encryptedDataStream = CreateEncryptedDataStream()) { encryptedDataStream.CopyTo(Stream.Null); } DocumentHeaders.Trailers(_reader); return(DocumentHeaders.HmacCalculator.Hmac == DocumentHeaders.Hmac); }
/// <summary> /// Decrypts the encrypted data to the given stream /// </summary> /// <param name="outputPlaintextStream">The resulting plain text stream.</param> public void DecryptTo(Stream outputPlaintextStream) { if (outputPlaintextStream == null) { throw new ArgumentNullException("outputPlaintextStream"); } if (!PassphraseIsValid) { throw new InternalErrorException("Passphrase is not valid!"); } using (Stream encryptedDataStream = CreateEncryptedDataStream()) { encryptedDataStream.DecryptTo(outputPlaintextStream, DocumentHeaders.DataCrypto().DecryptingTransform(), DocumentHeaders.IsCompressed); } DocumentHeaders.Trailers(_reader); if (DocumentHeaders.HmacCalculator.Hmac != DocumentHeaders.Hmac) { throw new Axantum.AxCrypt.Core.Runtime.IncorrectDataException("HMAC validation error.", ErrorStatus.HmacValidationError); } }