public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var tag = new Asn1Tag();
            buffer.Mark();

            var num = buffer.DecodeTagAndLength(tag);

            if (tag.Equals(0, 0, NullTypeCode))
            {
                buffer.Reset();
                var element = new NullParams();

                SetElement(Null, element);
                Element.Decode(buffer, true, num);
            }
            else
            {
                if (!tag.Equals(0, 0x20, SequenceTypeCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidChoiceOptionTagException, tag, buffer.ByteCount);
                }

                buffer.Reset();
                var parameters = new GostR34102001PublicKeyParameters();

                SetElement(Params, parameters);
                Element.Decode(buffer, true, num);
            }
        }
        public void DecodeParameters(byte[] data)
        {
            if (data == null)
            {
                throw ExceptionUtility.ArgumentNull("data");
            }

            try
            {
                var asnDecoder = new Asn1BerDecodeBuffer(data);
                var publicKeyParameters = new GostR34102001PublicKeyParameters();
                publicKeyParameters.Decode(asnDecoder);

                DigestParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.DigestParamSet);
                PublicKeyParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.PublicKeyParamSet);
                EncryptionParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.EncryptionParamSet);
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(GostR34102001PublicKeyParameters).FullName);
            }
        }
        public byte[] EncodeParameters()
        {
            byte[] data;

            var publicKeyParameters = new GostR34102001PublicKeyParameters();

            try
            {
                publicKeyParameters.DigestParamSet = Asn1ObjectIdentifier.FromOidString(DigestParamSet);
                publicKeyParameters.PublicKeyParamSet = Asn1ObjectIdentifier.FromOidString(PublicKeyParamSet);
                publicKeyParameters.EncryptionParamSet = CreateEncryptionParamSet(EncryptionParamSet);

                var asnEncoder = new Asn1BerEncodeBuffer();
                publicKeyParameters.Encode(asnEncoder);
                data = asnEncoder.MsgCopy;
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1EncodeError, typeof(GostR34102001PublicKeyParameters).FullName);
            }

            return data;
        }
        private static SubjectPublicKeyInfo EncodePublicKey(GostKeyExchangeParameters 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 = new GostR34102001PublicKeyParameters
                             {
                                 PublicKeyParamSet = Asn1ObjectIdentifier.FromOidString(transportParameters.PublicKeyParamSet),
                                 DigestParamSet = Asn1ObjectIdentifier.FromOidString(transportParameters.DigestParamSet),
                                 EncryptionParamSet = CreateEncryptionParamSet(transportParameters.EncryptionParamSet)
                             };

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

            var publicKeyAlgOid = new Asn1ObjectIdentifier(GostR34102001Constants.IdGostR34102001);
            publicKeyInfo.Algorithm = new AlgorithmIdentifier(publicKeyAlgOid, new Asn1OpenType(asnEncoder.MsgCopy));

            return publicKeyInfo;
        }