protected Gost_R3410_KeyExchangeAlgorithm(ProviderType providerType, SafeProvHandleImpl provHandle, SafeKeyHandleImpl keyHandle, Gost_R3410_KeyExchangeParams keyExchangeParameters, int keySize, int signatureAlgId) : base(providerType)
        {
            if (provHandle == null)
            {
                throw ExceptionUtility.ArgumentNull(nameof(provHandle));
            }

            if (keyHandle == null)
            {
                throw ExceptionUtility.ArgumentNull(nameof(keyHandle));
            }

            if (keyExchangeParameters == null)
            {
                throw ExceptionUtility.ArgumentNull(nameof(keyExchangeParameters));
            }

            _provHandle            = provHandle.DangerousAddRef();
            _keyHandle             = keyHandle.DangerousAddRef();
            _keyExchangeParameters = keyExchangeParameters;
            _keySize        = keySize;
            _signatureAlgId = signatureAlgId;
        }
 public Gost_R3410_2001_KeyExchangeAlgorithm(ProviderType providerType, SafeProvHandleImpl provHandle, SafeKeyHandleImpl keyHandle, Gost_R3410_2001_KeyExchangeParams keyExchangeParameters, int keySize, int signatureAlgId)
     : base(providerType, provHandle, keyHandle, keyExchangeParameters, keySize, signatureAlgId)
 {
 }
Ejemplo n.º 3
0
 protected override Gost_R3410_2012_256_KeyExchangeAlgorithm CreateKeyExchangeAlgorithm(ProviderType providerType, SafeProvHandleImpl provHandle, SafeKeyHandleImpl keyHandle, Gost_R3410_2012_256_KeyExchangeParams keyExchangeParameters)
 {
     return(new Gost_R3410_2012_256_KeyExchangeAlgorithm(providerType, provHandle, keyHandle, keyExchangeParameters, KeySizeValue, SignatureAlgId));
 }
 protected override SafeHashHandleImpl CreateHashHandle(SafeProvHandleImpl providerHandle)
 {
     return(CryptoApiHelper.CreateHash_3411_2012_256(providerHandle));
 }
 internal Gost_R3411_2012_256_HashAlgorithm(ProviderType providerType, SafeProvHandleImpl providerHandle) : base(providerType, providerHandle, DefaultHashSizeValue)
 {
 }
 protected abstract TKeyAlgorithm CreateKeyExchangeAlgorithm(ProviderType providerType, SafeProvHandleImpl provHandle, SafeKeyHandleImpl keyHandle, TKeyParams keyExchangeParameters);
Ejemplo n.º 7
0
 protected abstract SafeHashHandleImpl CreateHashHandle(SafeProvHandleImpl providerHandle);
Ejemplo n.º 8
0
 internal Gost_R3411_HashAlgorithm(ProviderType providerType, SafeProvHandleImpl providerHandle, int hashSize) : base(providerType, hashSize)
 {
     _hashHandle = CreateHashHandle(providerHandle);
 }
Ejemplo n.º 9
0
        private static void GetKeyPairValue(CspParameters providerParams, bool randomKeyContainer, out SafeProvHandleImpl providerHandle, out SafeKeyHandleImpl keyHandle)
        {
            SafeProvHandleImpl resultProviderHandle = null;

            SafeKeyHandleImpl resultKeyHandle = null;

            try
            {
                resultProviderHandle = CreateProviderHandle(providerParams, randomKeyContainer);

                if (providerParams.ParentWindowHandle != IntPtr.Zero)
                {
                    CryptoApiHelper.SetProviderParameter(resultProviderHandle, providerParams.KeyNumber, Constants.PP_CLIENT_HWND, providerParams.ParentWindowHandle);
                }
                else if (providerParams.KeyPassword != null)
                {
                    SetSignatureKeyPassword(resultProviderHandle, providerParams.KeyPassword, providerParams.KeyNumber);
                }

                try
                {
                    resultKeyHandle = CryptoApiHelper.GetUserKey(resultProviderHandle, providerParams.KeyNumber);
                }
                catch (Exception exception)
                {
                    var errorCode = Marshal.GetHRForException(exception);

                    if (errorCode != 0)
                    {
                        if (((providerParams.Flags & CspProviderFlags.UseExistingKey) != CspProviderFlags.NoFlags) || (errorCode != Constants.NTE_NO_KEY))
                        {
                            throw;
                        }

                        resultKeyHandle = CryptoApiHelper.GenerateKey(resultProviderHandle, providerParams.KeyNumber, providerParams.Flags);
                    }
                }

                var keyAlgIdInverted = CryptoApiHelper.GetKeyParameter(resultKeyHandle, Constants.KP_ALGID);
                var keyAlgId         = keyAlgIdInverted[0] | (keyAlgIdInverted[1] << 8) | (keyAlgIdInverted[2] << 16) | (keyAlgIdInverted[3] << 24);

                if ((keyAlgId != Constants.CALG_DH_EL_SF) && (keyAlgId != Constants.CALG_GR3410EL))
                {
                    throw ExceptionUtility.NotSupported(Resources.KeyAlgorithmNotSupported);
                }
            }
            catch (Exception)
            {
                if (resultProviderHandle != null)
                {
                    resultProviderHandle.Close();
                }

                if (resultKeyHandle != null)
                {
                    resultKeyHandle.Close();
                }

                throw;
            }

            providerHandle = resultProviderHandle;
            keyHandle      = resultKeyHandle;
        }
Ejemplo n.º 10
0
 protected abstract SafeHashHandleImpl CreateHashHMAC(ProviderType providerType, SafeProvHandleImpl providerHandle, SafeKeyHandleImpl symKeyHandle);
Ejemplo n.º 11
0
 protected override SafeHashHandleImpl CreateHashHMAC(ProviderType providerType, SafeProvHandleImpl providerHandle, SafeKeyHandleImpl symKeyHandle)
 {
     return(CryptoApiHelper.CreateHashHMAC_2012_256(providerType, providerHandle, symKeyHandle));
 }