Esempio n. 1
0
        public Gost3411Hmac()
        {
            HashName = DefaultHashName;
            HashSizeValue = DefaultHashSize;

            _keyAlgorithm = new Gost28147SymmetricAlgorithm();
            _hashHandle = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _keyAlgorithm.InternalKeyHandle);
        }
Esempio n. 2
0
        public Gost3411Hmac(Gost28147SymmetricAlgorithmBase keyAlgorithm)
        {
            if (keyAlgorithm == null)
            {
                throw ExceptionUtility.ArgumentNull("keyAlgorithm");
            }

            HashName = DefaultHashName;
            HashSizeValue = DefaultHashSize;

            _keyAlgorithm = DuplicateKeyAlg(keyAlgorithm);
            _hashHandle = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _keyAlgorithm.InternalKeyHandle);
        }
Esempio n. 3
0
        public Gost3411Hmac(byte[] key)
        {
            if (key == null)
            {
                throw ExceptionUtility.ArgumentNull("key");
            }

            HashName = DefaultHashName;
            HashSizeValue = DefaultHashSize;

            _keyAlgorithm = new Gost28147SymmetricAlgorithm { Key = key };
            _hashHandle = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _keyAlgorithm.InternalKeyHandle);
        }
Esempio n. 4
0
        public Gost3411Prf(Gost28147SymmetricAlgorithmBase key, byte[] label, byte[] seed)
            : this(label, seed)
        {
            if (key == null)
            {
                throw ExceptionUtility.ArgumentNull("key");
            }

            _hashHmacHandle = SafeHashHandleImpl.InvalidHandle;
            _buffer = new byte[_labelAndSeed.Length + 32];

            var gostSymmetricAlgorithm = key as Gost28147SymmetricAlgorithm;

            _key = (gostSymmetricAlgorithm != null)
                ? new Gost28147SymmetricAlgorithm(gostSymmetricAlgorithm.InternalProvHandle, gostSymmetricAlgorithm.InternalKeyHandle)
                : new Gost28147SymmetricAlgorithm { Key = key.Key };
        }
Esempio n. 5
0
        private void InitializeHmac()
        {
            var hashHmacHandle = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _key.InternalKeyHandle);

            _hashHmacHandle.TryDispose();

            _hashHmacHandle = hashHmacHandle;
        }
Esempio n. 6
0
        public override void Initialize()
        {
            var hashHmacHandle = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _keyAlgorithm.InternalKeyHandle);

            _hashHandle.TryDispose();

            _hashHandle = hashHmacHandle;
        }
Esempio n. 7
0
 public static extern bool CryptGetHashParam([In] SafeHashHandleImpl hHash, [In] uint dwParam, [In][Out] byte[] pbData, ref uint pdwDataLen, [In] uint dwFlags);
 public override void Initialize()
 {
     _hashHandle.TryDispose();
     _hashHandle = null;
 }
Esempio n. 9
0
 public static extern bool CryptVerifySignature([In] SafeHashHandleImpl hHash, [In][Out] byte[] pbSignature, uint pdwSigLen, [In] SafeKeyHandleImpl hPubKey, [MarshalAs(UnmanagedType.LPStr)] StringBuilder sDescription, [In] uint dwFlags);
Esempio n. 10
0
 public static extern bool CryptSignHash([In] SafeHashHandleImpl hHash, [In] uint dwKeySpec, [MarshalAs(UnmanagedType.LPStr)] StringBuilder sDescription, [In] uint dwFlags, [In][Out] byte[] pbSignature, ref uint pdwSigLen);
Esempio n. 11
0
 public static extern bool CryptDeriveKey([In] SafeProvHandleImpl hProv, [In] uint Algid, [In] SafeHashHandleImpl hBaseData, [In] uint dwFlags, [In][Out] ref SafeKeyHandleImpl phKey);
Esempio n. 12
0
        public static SafeKeyHandleImpl DeriveSymKey(SafeProvHandleImpl providerHandle, SafeHashHandleImpl hashHandle)
        {
            var symKeyHandle = SafeKeyHandleImpl.InvalidHandle;

            if (!CryptoApi.CryptDeriveKey(providerHandle, Constants.CALG_G28147, hashHandle, Constants.CRYPT_EXPORTABLE, ref symKeyHandle))
            {
                throw CreateWin32Error();
            }

            return(symKeyHandle);
        }
 public override void Initialize()
 {
     _hashHandle.TryDispose();
     _hashHandle = CryptoApiHelper.CreateHash(CryptoApiHelper.ProviderHandle);
 }
 public Gost3411HashAlgorithm()
 {
     _hashHandle = CryptoApiHelper.CreateHash(CryptoApiHelper.ProviderHandle);
 }
        private void InitHash()
        {
            var hProv = CryptoApiHelper.ProviderHandle;
            var hHash = CryptoApiHelper.CreateHashImit(hProv, _keyAlgorithm.InternalKeyHandle);

            _hashHandle = hHash;
        }
Esempio n. 16
0
 public static extern bool CryptCreateHash([In] SafeProvHandleImpl hProv, [In] uint Algid, [In] SafeKeyHandleImpl hKey, [In] uint dwFlags, [In][Out] ref SafeHashHandleImpl phHash);
Esempio n. 17
0
        public Gost3411Prf(byte[] key, byte[] label, byte[] seed)
            : this(label, seed)
        {
            if (key == null)
            {
                throw ExceptionUtility.ArgumentNull("key");
            }

            if (key.Length != 32)
            {
                throw ExceptionUtility.Argument("key", Resources.InvalidHashSize);
            }

            _hashHmacHandle = SafeHashHandleImpl.InvalidHandle;
            _buffer = new byte[_labelAndSeed.Length + 32];

            using (var keyHandle = CryptoApiHelper.ImportBulkSessionKey(CryptoApiHelper.ProviderHandle, key, CryptoApiHelper.RandomNumberGenerator))
            {
                _key = new Gost28147SymmetricAlgorithm(CryptoApiHelper.ProviderHandle, keyHandle);
            }
        }
Esempio n. 18
0
        public static bool VerifySign(SafeProvHandleImpl providerHandle, SafeHashHandleImpl hashHandle, SafeKeyHandleImpl keyHandle, byte[] hashValue, byte[] signatureValue)
        {
            SetHashValue(hashHandle, hashValue);

            return(CryptoApi.CryptVerifySignature(hashHandle, signatureValue, (uint)signatureValue.Length, keyHandle, null, 0));
        }