Пример #1
0
        /// <summary>
        /// Verify a message with password based MAC protection.
        /// </summary>
        /// <param name="pkMacBuilder">MAC builder that can be used to construct the appropriate MacCalculator</param>
        /// <param name="password">the MAC password</param>
        /// <returns>true if the passed in password and MAC builder verify the message, false otherwise.</returns>
        /// <exception cref="InvalidOperationException">if algorithm not MAC based, or an exception is thrown verifying the MAC.</exception>
        public bool Verify(PKMacBuilder pkMacBuilder, char[] password)
        {
            if (!CmpObjectIdentifiers.passwordBasedMac.Equals(pkiMessage.Header.ProtectionAlg.Algorithm))
            {
                throw new InvalidOperationException("protection algorithm is not mac based");
            }

            PbmParameter parameter = PbmParameter.GetInstance(pkiMessage.Header.ProtectionAlg.Parameters);

            pkMacBuilder.SetParameters(parameter);

            IBlockResult result = (IBlockResult)Process(pkMacBuilder.Build(password).CreateCalculator());

            return(Arrays.ConstantTimeAreEqual(result.Collect(), this.pkiMessage.Protection.GetBytes()));
        }
 public byte[] CollectDigest()
 {
     return(digResult.Collect());
 }
 public byte[] Collect()
 {
     return(sigResult.Collect());
 }