Exemplo n.º 1
0
        /// <summary>
        /// Calls EVP_VerifyFinal()
        /// </summary>
        /// <param name="md"></param>
        /// <param name="bio"></param>
        /// <param name="sig"></param>
        /// <param name="pkey"></param>
        /// <returns></returns>
        public static bool Verify(MessageDigest md, BIO bio, byte[] sig, CryptoKey pkey)
        {
            BIO bmd = BIO.MessageDigest(md);

            bmd.Push(bio);

            while (true)
            {
                ArraySegment <byte> bytes = bmd.ReadBytes(1024 * 4);
                if (bytes.Count == 0)
                {
                    break;
                }
            }

            MessageDigestContext ctx = new MessageDigestContext(bmd);

            int ret = Native.ExpectSuccess(Native.EVP_VerifyFinal(ctx.Handle, sig, (uint)sig.Length, pkey.Handle));

            return(ret == 1);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Calls BIO_get_md_ctx() then BIO_get_md()
 /// </summary>
 /// <param name="bio"></param>
 public MessageDigestContext(BIO bio)
     : base(Native.ExpectNonNull(Native.BIO_get_md_ctx(bio.Handle)), false)
 {
     this.md = new MessageDigest(Native.ExpectNonNull(Native.BIO_get_md(bio.Handle)), false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Calls EVP_MD_CTX_create() then EVP_MD_CTX_init()
 /// </summary>
 /// <param name="md"></param>
 public MessageDigestContext(MessageDigest md)
     : base(Native.EVP_MD_CTX_create(), true)
 {
     Native.EVP_MD_CTX_init(this.ptr);
     this.md = md;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Calls HMAC_Init_ex()
 /// </summary>
 /// <param name="key"></param>
 /// <param name="digest"></param>
 public void Init(byte[] key, MessageDigest digest)
 {
     Native.HMAC_Init_ex(this.ptr, key, key.Length, digest.Handle, IntPtr.Zero);
     this.digest_size = digest.Size;
     this.initialized = true;
 }