private byte[] EncodeKeyExchangeInternal(Gost_28147_89_SymmetricAlgorithm keyExchangeAlgorithm, int keyExchangeExportAlgId)
        {
            Gost_28147_89_KeyExchangeInfo keyExchangeInfo;

            SafeKeyHandleImpl keyExchangeHandle = null;

            try
            {
                var importedKeyBytes = CryptoApiHelper.EncodePublicBlob(_keyExchangeParameters, _keySize, _signatureAlgId);
                CryptoApiHelper.ImportCspBlob(importedKeyBytes, _provHandle, _keyHandle, out keyExchangeHandle);
                CryptoApiHelper.SetKeyExchangeExportAlgId(ProviderType, keyExchangeHandle, keyExchangeExportAlgId);

                var symKeyHandle = keyExchangeAlgorithm.GetSafeHandle();
                keyExchangeInfo = CryptoApiHelper.ExportKeyExchange(symKeyHandle, keyExchangeHandle);
            }
            finally
            {
                keyExchangeHandle.TryDispose();
            }

            return(keyExchangeInfo.Encode());
        }
Exemplo n.º 2
0
        private void InitDefaults(Gost_28147_89_SymmetricAlgorithm keyAlgorithm)
        {
            HashName = typeof(THash).Name;

            _keyAlgorithm = keyAlgorithm;
            _hmacHandle   = CreateHashHMAC(keyAlgorithm.ProviderType, CryptoApiHelper.GetProviderHandle(keyAlgorithm.ProviderType), keyAlgorithm.GetSafeHandle());
        }
Exemplo n.º 3
0
        public override void Initialize()
        {
            var hmacHandle = CreateHashHMAC(ProviderType, CryptoApiHelper.GetProviderHandle(ProviderType), _keyAlgorithm.GetSafeHandle());

            _hmacHandle.TryDispose();
            _hmacHandle = hmacHandle;
        }