Esempio n. 1
0
        public bool VerifyData(byte[] data, int offset, int count, byte[] signature)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (signature == null)
            {
                throw new ArgumentNullException("signature");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return(VerifyHash(hashValue, signature));
            }
        }
        public static byte[] SignData(
            this ECDsaCng ecdsaCng,
            byte[] data,
            int offset,
            int count)
        {
            Contract.Ensures(Contract.Result <byte[]>() != null);

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            using (var hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.Sha256, BCryptNative.ProviderName.MicrosoftPrimitiveProvider))
            {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();
                return(ecdsaCng.SignHash(hashValue));
            }
        }
Esempio n. 3
0
        public SHA512Cng()
        {
            Contract.Ensures(m_hashAlgorithm != null);

            m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.Sha512,
                                                      BCryptNative.ProviderName.MicrosoftPrimitiveProvider);
        }
Esempio n. 4
0
 public bool VerifyData(byte[] data, int offset, int count, byte[] signature)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if ((offset < 0) || (offset > data.Length))
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     if ((count < 0) || (count > (data.Length - offset)))
     {
         throw new ArgumentOutOfRangeException("count");
     }
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashCore(data, offset, count);
         byte[] hash = algorithm.HashFinal();
         return(this.VerifyHash(hash, signature));
     }
 }
 public MD5Cng()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms)
     {
         throw new InvalidOperationException(System.SR.GetString("Cryptography_NonCompliantFIPSAlgorithm"));
     }
     this.m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.MD5, "Microsoft Primitive Provider");
 }
 public MD5Cng()
 {
     if (CryptoConfig.AllowOnlyFipsAlgorithms)
     {
         throw new InvalidOperationException(System.SR.GetString("Cryptography_NonCompliantFIPSAlgorithm"));
     }
     this.m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.MD5, "Microsoft Primitive Provider");
 }
Esempio n. 7
0
        public MD5Cng() {
            Contract.Ensures(m_hashAlgorithm != null);

            if (CryptoConfig.AllowOnlyFipsAlgorithms) {
                throw new InvalidOperationException(SR.GetString(SR.Cryptography_NonCompliantFIPSAlgorithm));
            }

            m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.MD5,
                                                      BCryptNative.ProviderName.MicrosoftPrimitiveProvider);
        }
Esempio n. 8
0
        protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
        {
            // we're sealed and the base should have checked this before calling us
            Debug.Assert(data != null);
            Debug.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

            using (BCryptHashAlgorithm hasher = new BCryptHashAlgorithm(new CngAlgorithm(hashAlgorithm.Name), BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hasher.HashStream(data);
                return(hasher.HashFinal());
            }
        }
        public MD5Cng()
        {
            Contract.Ensures(m_hashAlgorithm != null);

            if (CryptoConfig.AllowOnlyFipsAlgorithms && LocalAppContextSwitches.UseLegacyFipsThrow)
            {
                throw new InvalidOperationException(SR.GetString(SR.Cryptography_NonCompliantFIPSAlgorithm));
            }

            m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.MD5,
                                                      BCryptNative.ProviderName.MicrosoftPrimitiveProvider);
        }
Esempio n. 10
0
 public byte[] SignData(Stream data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashStream(data);
         byte[] hash = algorithm.HashFinal();
         return(this.SignHash(hash));
     }
 }
Esempio n. 11
0
        protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
        {
            // we're sealed and the base should have checked this before calling us
            Debug.Assert(data != null);
            Debug.Assert(offset >= 0 && offset <= data.Length);
            Debug.Assert(count >= 0 && count <= data.Length - offset);
            Debug.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

            using (BCryptHashAlgorithm hasher = new BCryptHashAlgorithm(new CngAlgorithm(hashAlgorithm.Name), BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hasher.HashCore(data, offset, count);
                return(hasher.HashFinal());
            }
        }
Esempio n. 12
0
        public byte[] SignData(Stream data)
        {
            Contract.Ensures(Contract.Result <byte[]>() != null);

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashStream(data);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return(SignHash(hashValue));
            }
        }
Esempio n. 13
0
 public bool VerifyData(Stream data, byte[] signature)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashStream(data);
         byte[] hash = algorithm.HashFinal();
         return(this.VerifyHash(hash, signature));
     }
 }
Esempio n. 14
0
        public bool VerifyData(Stream data, byte[] signature)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (signature == null)
            {
                throw new ArgumentNullException("signature");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashStream(data);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return(VerifyHash(hashValue, signature));
            }
        }
Esempio n. 15
0
        public bool VerifyData(Stream data, byte[] signature) {
            if (data == null) {
                throw new ArgumentNullException("data");
            }
            if (signature == null) {
                throw new ArgumentNullException("signature");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashStream(data);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return VerifyHash(hashValue, signature);
            }
        }
Esempio n. 16
0
        public byte[] SignData(Stream data) {
            Contract.Ensures(Contract.Result<byte[]>() != null);

            if (data == null) {
                throw new ArgumentNullException("data");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashStream(data);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return SignHash(hashValue);
            }
        }
Esempio n. 17
0
        public bool VerifyData(byte[] data, int offset, int count, byte[] signature) {
            if (data == null) {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length) {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset) {
                throw new ArgumentOutOfRangeException("count");
            }
            if (signature == null) {
                throw new ArgumentNullException("signature");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return VerifyHash(hashValue, signature);
            }
        }
Esempio n. 18
0
        public SHA384Cng() {
            Contract.Ensures(m_hashAlgorithm != null);

            m_hashAlgorithm = new BCryptHashAlgorithm(CngAlgorithm.Sha384,
                                                      BCryptNative.ProviderName.MicrosoftPrimitiveProvider);
        }
Esempio n. 19
0
        public byte[] SignData(byte[] data, int offset, int count) {
            Contract.Ensures(Contract.Result<byte[]>() != null);

            if (data == null) {
                throw new ArgumentNullException("data");
            }
            if (offset < 0 || offset > data.Length) {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > data.Length - offset) {
                throw new ArgumentOutOfRangeException("count");
            }

            using (BCryptHashAlgorithm hashAlgorithm = new BCryptHashAlgorithm(HashAlgorithm, BCryptNative.ProviderName.MicrosoftPrimitiveProvider)) {
                hashAlgorithm.HashCore(data, offset, count);
                byte[] hashValue = hashAlgorithm.HashFinal();

                return SignHash(hashValue);
            }
        }
 public bool VerifyData(Stream data, byte[] signature)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashStream(data);
         byte[] hash = algorithm.HashFinal();
         return this.VerifyHash(hash, signature);
     }
 }
 public bool VerifyData(byte[] data, int offset, int count, byte[] signature)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if ((offset < 0) || (offset > data.Length))
     {
         throw new ArgumentOutOfRangeException("offset");
     }
     if ((count < 0) || (count > (data.Length - offset)))
     {
         throw new ArgumentOutOfRangeException("count");
     }
     if (signature == null)
     {
         throw new ArgumentNullException("signature");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashCore(data, offset, count);
         byte[] hash = algorithm.HashFinal();
         return this.VerifyHash(hash, signature);
     }
 }
 public byte[] SignData(Stream data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     using (BCryptHashAlgorithm algorithm = new BCryptHashAlgorithm(this.HashAlgorithm, "Microsoft Primitive Provider"))
     {
         algorithm.HashStream(data);
         byte[] hash = algorithm.HashFinal();
         return this.SignHash(hash);
     }
 }
Esempio n. 23
0
        protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
        {
            // we're sealed and the base should have checked this already
            Debug.Assert(data != null);
            Debug.Assert(offset >= 0 && offset <= data.Length);
            Debug.Assert(count >= 0 && count <= data.Length);
            Debug.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

            using (BCryptHashAlgorithm hasher = new BCryptHashAlgorithm(new CngAlgorithm(hashAlgorithm.Name), BCryptNative.ProviderName.MicrosoftPrimitiveProvider))
            {
                hasher.HashCore(data, offset, count);
                return hasher.HashFinal();
            }
        }
Esempio n. 24
0
        protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
        {
            // We're sealed and the base should have checked these alread.
            Debug.Assert(data != null);
            Debug.Assert(!String.IsNullOrEmpty(hashAlgorithm.Name));

            using (BCryptHashAlgorithm hasher = new BCryptHashAlgorithm(new CngAlgorithm(hashAlgorithm.Name), BCryptNative.ProviderName.MicrosoftPrimitiveProvider))
            {
                hasher.HashStream(data);
                return hasher.HashFinal();
            }
        }