Ejemplo n.º 1
0
        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();

                SetElement(Null, new NullParams());
                Element.Decode(buffer, true, num);
            }
            else
            {
                if (!tag.Equals(0, TagForm, TagIdCode))
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidChoiceOptionTagException, tag, buffer.ByteCount);
                }

                buffer.Reset();

                SetElement(Params, CreateParams());
                Element.Decode(buffer, true, num);
            }
        }
Ejemplo n.º 2
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var llen = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            Value           = buffer.DecodeRelOidContents(llen);
            buffer.TypeCode = RelativeOidTypeCode;
        }
        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 GostR341094PublicKeyParameters();

                SetElement(Params, parameters);
                Element.Decode(buffer, true, num);
            }
        }
Ejemplo n.º 4
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = implicitLength;

            // decode CHOICE

            Asn1Tag tag = new Asn1Tag();

            buffer.Mark();
            int len = buffer.DecodeTagAndLength(tag);

            if (tag.Equals(Asn1Tag.Universal, Asn1Tag.PRIM, 5))
            {
                buffer.Reset();
                NULLParams null_ = new NULLParams();
                SetElement(_NULL_, null_);
                Element.Decode(buffer, true, len);
            }
            else if (tag.Equals(Asn1Tag.Universal, Asn1Tag.CONS, 16))
            {
                buffer.Reset();
                GostR3410_2012_PublicKeyParameters params_ = new GostR3410_2012_PublicKeyParameters();
                SetElement(_PARAMS_, params_);
                Element.Decode(buffer, true, len);
            }
            else
            {
                throw new Exception("Asn1InvalidChoiceOptionException (buffer, tag)");
            }
        }
Ejemplo n.º 5
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            _value          = DecodeValue(buffer, length);
            buffer.TypeCode = 2;
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            EncryptedKey    = null;
            EncryptedParams = null;

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0x20, SequenceTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptedKey = new Gost_28147_89_EncryptedKey();
            EncryptedKey.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0x20, SequenceTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptedParams = new Gost_28147_89_KeyWrapParams();
            EncryptedParams.Decode(buffer, true, parsedLen.Value);
        }
Ejemplo n.º 7
0
        public void DecodePublicKey(byte[] data, int algId)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            Asn1OctetString publicKey;
            var             asnDecoder = new Asn1BerDecodeBuffer(data);

            if (algId == GostConstants.CALG_GR3410EL)
            {
                publicKey = new Gost3410PublicKey();
            }
            else if (algId == GostConstants.CALG_GR3410_12_256)
            {
                publicKey = new Gost3410_2012_256PublicKey();
            }
            else if (algId == GostConstants.CALG_GR3410_12_512)
            {
                publicKey = new Gost3410_2012_512PublicKey();
            }
            else
            {
                throw new CryptographicException(
                          SR.Cryptography_CSP_WrongKeySpec);
            }
            publicKey.Decode(asnDecoder);

            _publicKey = publicKey.Value;
        }
Ejemplo n.º 8
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var length = explicitTagging ? MatchTag(buffer, Tag) : implicitLength;

            Value           = Asn1RunTime.DecodeIntValue(buffer, length, true);
            buffer.TypeCode = BigIntegerTypeCode;
        }
Ejemplo n.º 9
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Algorithm  = null;
            Parameters = null;

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            Algorithm = new Asn1ObjectIdentifier();
            Algorithm.Decode(buffer, true, parsedLen.Value);

            if (!context.Expired())
            {
                Parameters = new Asn1OpenType();
                Parameters.Decode(buffer, true, 0);
            }

            CheckAlg(true);
        }
Ejemplo n.º 10
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw new Exception("Asn1MissingRequiredException");
            }

            PublicKeyParamSet = new Asn1ObjectIdentifier();
            PublicKeyParamSet.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw new Exception("Asn1MissingRequiredException");
            }

            DigestParamSet = new Asn1ObjectIdentifier();
            DigestParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                EncryptionParamSet = new Gost2814789ParamSet();
                EncryptionParamSet.Decode(buffer, true, parsedLen.Value);
            }
        }
Ejemplo n.º 11
0
        private void CheckAlg(bool decode)
        {
            AlgorithmId algorithmId = null;

            foreach (var alg in PkiConstants.SupportedAlgorithms)
            {
                if (alg.Id.Equals(Algorithm))
                {
                    algorithmId = alg;
                    break;
                }
            }

            if ((algorithmId != null) && ((decode && (Parameters != null)) && (algorithmId.Type != null)))
            {
                try
                {
                    var buffer = new Asn1BerDecodeBuffer(((Asn1OpenType)Parameters).Value);
                    Parameters = (Asn1Type)Activator.CreateInstance(algorithmId.Type.GetType());
                    Parameters.Decode(buffer, true, 0);
                    buffer.InvokeEndElement("parameters", -1);
                }
                catch (Exception exception)
                {
                    Asn1Util.WriteStackTrace(exception, Console.Error);
                    throw ExceptionUtility.CryptographicException(Resources.Asn1TableConstraint);
                }
            }
        }
Ejemplo n.º 12
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
            MatchTag (buffer, Asn1Tag.SEQUENCE) : implicitLength;

             Init ();

             // decode SEQUENCE

             Asn1BerDecodeContext _context =
            new Asn1BerDecodeContext (buffer, llen);

             IntHolder elemLen = new IntHolder();

             // decode type

             if (_context.MatchElemTag (Asn1Tag.UNIV, Asn1Tag.PRIM, 4, elemLen, false)) {
            type = new AttributeDescription();
            type.Decode (buffer, true, elemLen.mValue);
             }
             else throw new Asn1MissingRequiredException (buffer);

             // decode vals

             if (_context.MatchElemTag (Asn1Tag.UNIV, Asn1Tag.CONS, 17, elemLen, false)) {
            vals = new _SetOfAttributeValue();
            vals.Decode (buffer, true, elemLen.mValue);
             }
             else throw new Asn1MissingRequiredException (buffer);

             if (explicitTagging && llen == Asn1Status.INDEFLEN) {
            MatchTag (buffer, Asn1Tag.EOC);
             }
        }
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0x20, 0x10, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            Algorithm = new AlgorithmIdentifier();
            Algorithm.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0, 3, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            SubjectPublicKey = new Asn1BitString();
            SubjectPublicKey.Decode(buffer, true, parsedLen.Value);
        }
Ejemplo n.º 14
0
 public Asn1BerDecodeContext(Asn1BerDecodeBuffer decodeBuffer, int elemLength)
 {
     _decodeBuffer    = decodeBuffer;
     _decBufByteCount = decodeBuffer.ByteCount;
     _elemLength      = elemLength;
     _tagHolder       = new Asn1Tag();
 }
Ejemplo n.º 15
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode sessionEncryptedKey

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.CONS, 16, elemLen, false))
            {
                sessionEncryptedKey = new Gost28147_89_EncryptedKey();
                sessionEncryptedKey.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }

            // decode transportParameters

            if (context.MatchElemTag(Asn1Tag.CTXT, Asn1Tag.CONS, 0, elemLen, true))
            {
                transportParameters = new GostR3410_TransportParameters();
                transportParameters.Decode(buffer, false, elemLen.Value);
            }
        }
Ejemplo n.º 16
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            _publicKeyParamSet = new Asn1ObjectIdentifier();
            _publicKeyParamSet.Decode(buffer, true, parsedLen.Value);

            if (!context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            _digestParamSet = new Asn1ObjectIdentifier();
            _digestParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0, 0, 6, parsedLen, false))
            {
                _encryptionParamSet = new Gost2814789ParamSet();
                _encryptionParamSet.Decode(buffer, true, parsedLen.Value);
            }
        }
Ejemplo n.º 17
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            EncryptionParamSet = null;
            Ukm = null;

            var context   = new Asn1BerDecodeContext(buffer, elemLength);
            var parsedLen = new IntHolder();

            if (!context.MatchElemTag(0, 0, ObjectIdentifierTypeCode, parsedLen, false))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount);
            }

            EncryptionParamSet = new Gost_28147_89_ParamSet();
            EncryptionParamSet.Decode(buffer, true, parsedLen.Value);

            if (context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false))
            {
                Ukm = new Asn1OctetString();
                Ukm.Decode(buffer, true, parsedLen.Value);

                if (Ukm.Length != 8)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, nameof(Ukm.Length), Ukm.Length);
                }
            }
        }
Ejemplo n.º 18
0
 public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
 {
     base.Decode(buffer, explicitTagging, implicitLength);
     if (Length != 0x40)
     {
         throw new Exception("Asn1ConsVioException");
     }
 }
Ejemplo n.º 19
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            base.Decode(buffer, explicitTagging, implicitLength);

            if ((Length < 1) || (Length > 4))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, nameof(Length), Length);
            }
        }
Ejemplo n.º 20
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            if (explicitTagging)
            {
                MatchTag(buffer, Tag);
            }

            buffer.TypeCode = NullTypeCode;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Декодирование ASN.1 структуры транспорта.
        /// </summary>
        ///
        /// <param name="data">ASN.1 закодированная структура.</param>
        /// <param name="transport">ГОСТ Р 34.10 транспорт.</param>
        ///
        /// <argnull name="data" />
        /// <exception cref="CryptographicException">При ошибках
        /// декодирования исходной структуры.</exception>
        public static void DecodeGostKeyTransport(byte[] data,
                                                  GostKeyTransportObject transport)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            try
            {
                Asn1BerDecodeBuffer    buffer       = new Asn1BerDecodeBuffer(data);
                GostR3410_KeyTransport asnTransport =
                    new GostR3410_KeyTransport();
                asnTransport.Decode(buffer);
                transport.sessionEncryptedKey_ = new GostWrappedKeyObject();
                transport.sessionEncryptedKey_._encryptedKey =
                    asnTransport.sessionEncryptedKey.encryptedKey.Value;
                transport.sessionEncryptedKey_._mac =
                    asnTransport.sessionEncryptedKey.macKey.Value;
                transport.sessionEncryptedKey_._ukm =
                    asnTransport.transportParameters.ukm.Value;
                transport.sessionEncryptedKey_._encryptionParamSet =
                    toString(asnTransport.transportParameters.encryptionParamSet);
                // Для корректной ошибки, а не ArgumentException
                string algoid = toString(
                    asnTransport.transportParameters.ephemeralPublicKey.
                    algorithm.algorithm);

                if (algoid.Equals(GostConstants.OID_CP_GOST_R3410EL))
                {
                    transport.transportParameters_ = UnpackPublicKeyInfo2001(
                        asnTransport.transportParameters.ephemeralPublicKey);
                }
                else if (algoid.Equals(GostConstants.OID_CP_GOST_R3410_12_256) ||
                         (algoid.Equals(GostConstants.OID_CP_GOST_R3410_12_512)))
                {
                    transport.transportParameters_ = UnpackPublicKeyInfo2012(
                        asnTransport.transportParameters.ephemeralPublicKey);
                }
                else
                {
                    throw new CryptographicException(
                              "Resources.Cryptography_ASN1_Decode_Alg " + algoid);
                }
            }
            catch (Exception e)
            {
                throw new CryptographicException(
                          "Resources.Cryptography_ASN1_DecodeWithException " +
                          "GostR3410_KeyTransport", e);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Декодирование ASN.1 структуры зашифрованного общего секрета.
        /// </summary>
        ///
        /// <param name="data">ASN.1 закодированная структура.</param>
        /// <param name="wk">Зашифрованный ГОСТ Р 34.10 ключ.</param>
        ///
        /// <argnull name="data" />
        /// <argnull name="wk" />
        /// <exception cref="CryptographicException">При ошибках
        /// декодирования исходной структуры.</exception>
        public static void DecodeXmlGostR3410WrappedKey(byte[] data,
                                                        GostWrappedKeyObject wk)
        {
            Asn1BerDecodeBuffer buffer  = new Asn1BerDecodeBuffer(data);
            GostR3410_KeyWrap   wrapped = new GostR3410_KeyWrap();

            wrapped.Decode(buffer);
            wk._encryptedKey       = wrapped.encryptedKey.encryptedKey.Value;
            wk._mac                = wrapped.encryptedKey.macKey.Value;
            wk._ukm                = wrapped.encryptedParameters.ukm.Value;
            wk._encryptionParamSet = ToString(
                wrapped.encryptedParameters.encryptionParamSet);
        }
Ejemplo n.º 23
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode encryptionParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                encryptionParamSet = new Gost28147_89_ParamSet();
                encryptionParamSet.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }

            // decode ephemeralPublicKey

            if (context.MatchElemTag(Asn1Tag.CTXT, Asn1Tag.CONS, 0, elemLen, true))
            {
                ephemeralPublicKey = new SubjectPublicKeyInfo();
                ephemeralPublicKey.Decode(buffer, false, elemLen.Value);
            }

            // decode ukm

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
            {
                ukm = new Asn1OctetString();
                ukm.Decode(buffer, true, elemLen.Value);
                if (!(ukm.Length == 8))
                {
                    throw new Exception("Asn1ConsVioException (ukm.Length, ukm.Length)");
                }
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }
        }
Ejemplo n.º 24
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode encryptedKey

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
            {
                encryptedKey = new Gost28147_89_Key();
                encryptedKey.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException");
            }

            // decode maskKey

            if (context.MatchElemTag(Asn1Tag.CTXT, Asn1Tag.PRIM, 0, elemLen, true))
            {
                maskKey = new Gost28147_89_Key();
                maskKey.Decode(buffer, false, elemLen.Value);
            }

            // decode macKey

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 4, elemLen, false))
            {
                macKey = new Gost28147_89_MAC();
                macKey.Decode(buffer, true, elemLen.Value);
                if (!(macKey.Length == 4))
                {
                    throw new Exception("Asn1ConsVioException");
                }
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException");
            }
        }
Ejemplo n.º 25
0
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode encryptionParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                encryptionParamSet = new Gost28147_89_ParamSet();
                encryptionParamSet.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException");
            }

            // decode extElem1

            if (!context.Expired())
            {
                Asn1Tag _tag = buffer.PeekTag();
                if (_tag.Equals(Asn1Tag.Universal, Asn1Tag.PRIM, 6))
                {
                    throw new Exception("Asn1SeqOrderException");
                }
                else
                {
                    extElem1 = new Asn1OpenExt();
                    while (!context.Expired())
                    {
                        extElem1.DecodeComponent(buffer);
                    }
                }
            }
            else
            {
                extElem1 = null;
            }
        }
Ejemplo n.º 26
0
        public void DecodePublicKey(byte[] data)
        {
            if (data == null)
            {
                throw new Exception("ArgumentNull - data");
            }

            var asnDecoder = new Asn1BerDecodeBuffer(data);
            var publicKey  = new GostR34102001PublicKey();

            publicKey.Decode(asnDecoder);

            PublicKey = publicKey.Value;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Декодирование ASN.1 структуры параметров шифрования.
        /// </summary>
        ///
        /// <param name="data">ASN.1 закодированные параметры
        /// шифровыания.</param>
        ///
        /// <returns>Строковое представление OID шифрования.</returns>
        ///
        /// <argnull name="data" />
        /// <exception cref="CryptographicException">При ошибках
        /// декодирования исходной структуры.</exception>
        public static string DecodeGost28147_89_BlobParameters(
            byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            Asn1BerDecodeBuffer buffer =
                new Asn1BerDecodeBuffer(data);
            Gost28147_89_BlobParameters asnParams =
                new Gost28147_89_BlobParameters();

            asnParams.Decode(buffer);
            return(ToString(asnParams.encryptionParamSet));
        }
Ejemplo n.º 28
0
        public void DecodeParameters(byte[] data)
        {
            if (data == null)
            {
                throw new Exception("ArgumentNull - data");
            }

            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);
        }
        public override void Decode
            (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            int llen = (explicitTagging) ?
                       MatchTag(buffer, Asn1Tag.Sequence) : implicitLength;

            Init();

            // decode SEQUENCE

            Asn1BerDecodeContext context =
                new Asn1BerDecodeContext(buffer, llen);

            IntHolder elemLen = new IntHolder();

            // decode publicKeyParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                publicKeyParamSet = new Asn1ObjectIdentifier();
                publicKeyParamSet.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }

            // decode digestParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                digestParamSet = new Asn1ObjectIdentifier();
                digestParamSet.Decode(buffer, true, elemLen.Value);
            }
            else
            {
                throw new Exception("Asn1MissingRequiredException (buffer)");
            }

            // decode encryptionParamSet

            if (context.MatchElemTag(Asn1Tag.Universal, Asn1Tag.PRIM, 6, elemLen, false))
            {
                encryptionParamSet = new Gost28147_89_ParamSet();
                encryptionParamSet.Decode(buffer, true, elemLen.Value);
            }
        }
Ejemplo n.º 30
0
        public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength)
        {
            if (explicitTagging)
            {
                MatchTag(buffer, Tag);
            }

            var num = buffer.Read();

            if (num < 0)
            {
                throw new Exception("Asn1 End Of Buffer Exception");
            }

            buffer.TypeCode = BooleanTypeCode;
            Value           = num != 0;
        }
Ejemplo n.º 31
0
        public void DecodeParameters(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }


            var asnDecoder          = new Asn1BerDecodeBuffer(data);
            var publicKeyParameters = new Gost3410PublicKeyParameters();

            publicKeyParameters.Decode(asnDecoder);

            _digestParamSet     = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.DigestParamSet);
            _publicKeyParamSet  = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.PublicKeyParamSet);
            _encryptionParamSet = Asn1ObjectIdentifier.ToOidString(publicKeyParameters.EncryptionParamSet);
        }