示例#1
0
        private static Gost28147SymmetricAlgorithm DuplicateKeyAlg(Gost28147 keyAlgorithm)
        {
            var keySymmetricAlgorithm = keyAlgorithm as Gost28147SymmetricAlgorithm;

            return((keySymmetricAlgorithm != null)
                                ? new Gost28147SymmetricAlgorithm(keySymmetricAlgorithm.InternalProvHandle, keySymmetricAlgorithm.InternalKeyHandle)
                                : new Gost28147SymmetricAlgorithm {
                Key = keyAlgorithm.Key
            });
        }
        public Gost28147ImitHashAlgorithm(Gost28147 key)
        {
            if (key == null)
            {
                throw ExceptionUtility.ArgumentNull("key");
            }

            KeyValue      = null;
            HashSizeValue = DefaultHashSize;

            _keyAlgorithm = DuplicateKeyAlg(key);
        }
示例#3
0
        public Gost3411Hmac(Gost28147 keyAlgorithm)
        {
            if (keyAlgorithm == null)
            {
                throw ExceptionUtility.ArgumentNull("keyAlgorithm");
            }

            HashName      = DefaultHashName;
            HashSizeValue = DefaultHashSize;

            _keyAlgorithm = DuplicateKeyAlg(keyAlgorithm);
            _hashHandle   = CryptoApiHelper.CreateHashHmac(CryptoApiHelper.ProviderHandle, _keyAlgorithm.InternalKeyHandle, GostCryptoConfig.ProviderType == ProviderTypes.VipNet ? Constants.CALG_GR3411_HMAC34 : Constants.CALG_GR3411_HMAC);
        }
示例#4
0
        public Gost3411Prf(Gost28147 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
            };
        }
        public override byte[] EncodePrivateKey(Gost28147 keyExchangeAlgorithm, GostKeyExchangeExportMethod keyExchangeExportMethod)
        {
            if (keyExchangeAlgorithm == null)
            {
                throw ExceptionUtility.ArgumentNull("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("keyExchangeExportMethod");
            }

            var currentSessionKey = keyExchangeAlgorithm as Gost28147SymmetricAlgorithm;

            if (currentSessionKey == null)
            {
                using (var derivedSessinKey = new Gost28147SymmetricAlgorithm())
                {
                    derivedSessinKey.Key = keyExchangeAlgorithm.Key;

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

            return(EncodePrivateKeyInternal(currentSessionKey, keyExchangeExportAlgId));
        }
示例#6
0
 /// <summary>
 /// Экспортирует (шифрует) секретный ключ.
 /// </summary>
 /// <param name="keyExchangeAlgorithm">Общий секретный ключ.</param>
 /// <param name="keyExchangeExportMethod">Алгоритм экспорта общего секретного ключа.</param>
 public abstract byte[] EncodePrivateKey(Gost28147 keyExchangeAlgorithm, GostKeyExchangeExportMethod keyExchangeExportMethod);