예제 #1
0
        public Gost_28147_89_ImitHashAlgorithm(Gost_28147_89_SymmetricAlgorithmBase key) : base(key.ProviderType, DefaultHashSize)
        {
            if (key == null)
            {
                throw ExceptionUtility.ArgumentNull(nameof(key));
            }

            KeyValue = null;

            _keyAlgorithm = Gost_28147_89_SymmetricAlgorithm.CreateFromKey(key);
        }
        private byte[] EncodePrivateKeyInternal(Gost_28147_89_SymmetricAlgorithm sessionKey, int keyExchangeExportAlgId)
        {
            var hSessionKey = sessionKey.GetSafeHandle();

            using (var keyHandle = CryptoApiHelper.DuplicateKey(this.GetSafeHandle()))
            {
                CryptoApiHelper.SetKeyExchangeExportAlgId(ProviderType, keyHandle, keyExchangeExportAlgId);
                CryptoApiHelper.SetKeyParameter(keyHandle, Constants.KP_IV, IV);

                var keyExchangeInfo = CryptoApiHelper.ExportKeyExchange(hSessionKey, keyHandle);

                return(keyExchangeInfo.Encode());
            }
        }
        public override byte[] EncodePrivateKey(Gost_28147_89_SymmetricAlgorithmBase keyExchangeAlgorithm, GostKeyExchangeExportMethod keyExchangeExportMethod)
        {
            if (keyExchangeAlgorithm == null)
            {
                throw ExceptionUtility.ArgumentNull(nameof(keyExchangeAlgorithm));
            }

            int keyExchangeExportAlgId;

            if (keyExchangeExportMethod == GostKeyExchangeExportMethod.GostKeyExport)
            {
                keyExchangeExportAlgId = Constants.CALG_SIMPLE_EXPORT;
            }
            else if (keyExchangeExportMethod == GostKeyExchangeExportMethod.CryptoProKeyExport)
            {
                keyExchangeExportAlgId = Constants.CALG_PRO_EXPORT;
            }
            else
            {
                throw ExceptionUtility.ArgumentOutOfRange(nameof(keyExchangeExportMethod));
            }

            var currentSessionKey = keyExchangeAlgorithm as Gost_28147_89_SymmetricAlgorithm;

            if (currentSessionKey == null)
            {
                using (var derivedSessionKey = new Gost_28147_89_SymmetricAlgorithm(ProviderType))
                {
                    derivedSessionKey.Key = keyExchangeAlgorithm.Key;

                    return(EncodePrivateKeyInternal(derivedSessionKey, keyExchangeExportAlgId));
                }
            }

            return(EncodePrivateKeyInternal(currentSessionKey, keyExchangeExportAlgId));
        }
예제 #4
0
 public Gost_28147_89_ImitHashAlgorithm(ProviderType providerType) : base(providerType, DefaultHashSize)
 {
     _keyAlgorithm = new Gost_28147_89_SymmetricAlgorithm(ProviderType);
 }