示例#1
0
        private SubjectPublicKeyInfo EncodePublicKey(Gost_R3410_KeyExchangeParams transportParameters)
        {
            var asnEncoder = new Asn1BerEncodeBuffer();
            var publicKey  = new Asn1OctetString(transportParameters.PublicKey);

            publicKey.Encode(asnEncoder);

            var publicKeyValue = asnEncoder.MsgCopy;

            var publicKeyInfo = new SubjectPublicKeyInfo
            {
                SubjectPublicKey = new Asn1BitString(publicKeyValue.Length * 8, publicKeyValue)
            };

            var publicKeyParams = CreatePublicKeyParams();

            publicKeyParams.PublicKeyParamSet  = new Asn1ObjectIdentifier(OidValue.FromString(transportParameters.PublicKeyParamSet));
            publicKeyParams.DigestParamSet     = new Asn1ObjectIdentifier(OidValue.FromString(transportParameters.DigestParamSet));
            publicKeyParams.EncryptionParamSet = Gost_28147_89_ParamSet.FromString(transportParameters.EncryptionParamSet);

            asnEncoder.Reset();
            publicKeyParams.Encode(asnEncoder);

            var publicKeyAlgOid = new Asn1ObjectIdentifier(KeyAlgorithm);

            publicKeyInfo.Algorithm = new AlgorithmIdentifier(publicKeyAlgOid, new Asn1OpenType(asnEncoder.MsgCopy));

            return(publicKeyInfo);
        }
示例#2
0
        /// <summary>
        /// Зашифровать параметры.
        /// </summary>
        public byte[] EncodeParameters()
        {
            byte[] data;

            try
            {
                var publicKeyParams = CreatePublicKeyParams();
                publicKeyParams.DigestParamSet     = new Asn1ObjectIdentifier(OidValue.FromString(DigestParamSet));
                publicKeyParams.PublicKeyParamSet  = new Asn1ObjectIdentifier(OidValue.FromString(PublicKeyParamSet));
                publicKeyParams.EncryptionParamSet = Gost_28147_89_ParamSet.FromString(EncryptionParamSet);

                var asnEncoder = new Asn1BerEncodeBuffer();
                publicKeyParams.Encode(asnEncoder);
                data = asnEncoder.MsgCopy;
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1EncodeError, nameof(Gost_R3410_PublicKeyParams));
            }

            return(data);
        }
 public static Gost_28147_89_ParamSet FromString(string value)
 {
     return((value != null) ? new Gost_28147_89_ParamSet(OidValue.FromString(value)) : null);
 }
示例#4
0
 public static Asn1ObjectIdentifier FromString(string value)
 {
     return(string.IsNullOrEmpty(value) ? null : new Asn1ObjectIdentifier(OidValue.FromString(value)));
 }