Exemplo n.º 1
0
        /**
         * Verifies a signature for any data previously added via {@link #update(byte[])}.
         * @param sig a signature
         * @return whether the signature is valid
         * @throws NtruException if <code>initVerify</code> was not called
         */
        public bool verify(byte[] sig)
        {
            if (hashAlg == null || verificationKey == null)
            {
                throw new NtruException("Call initVerify first!");
            }

            byte[] msgHash = new byte[hashAlg.DigestSize];
            hashAlg.DoFinal(msgHash, 0);
            return(verifyHash(msgHash, sig, verificationKey));
        }
Exemplo n.º 2
0
        public void Example_ComputeHash()
        {
            byte[] first  = Encoding.ASCII.GetBytes("Hello ");
            byte[] second = Encoding.ASCII.GetBytes("world!");

            using SHA256 sha = SHA256.Create();
            sha.Update(first);
            sha.Update(second);

            byte[] hash   = sha.DoFinal();
            string result = $"SHA256 of 'Hello world!' is {HexConvertor.GetString(hash)}";

            Assert.IsNotNull(result);
        }