Ejemplo n.º 1
0
        public static AsnBitstring Decode(byte[] source, ref int pos)
        {
            AsnBitstring instance = new AsnBitstring();

            //CheckContextTag(source, ref pos);
            pos++;

            long length = instance.GetLength(source, ref pos);

            // first byte of a bit string denotes how many unused bits are at the end of the bit string
            instance.unused = source[pos];
            pos++;
            length--;

            //Console.WriteLine("Bit string, length = {0}, unused = {1}", length, unused);
            instance.value = new byte[length];
            Array.Copy(source, pos, instance.value, 0, (int)length);
            //foreach (var b in value)
            //{
            //    Console.Write(b.ToString("X2"));
            //}

            //Console.WriteLine("");
            pos += (int)length;

            return(instance);
        }
Ejemplo n.º 2
0
        public static AsnCertificationRequest Decode(byte[] source, ref int pos)
        {
            AsnCertificationRequest instance = new AsnCertificationRequest();

            //CheckContextTag(source, ref pos);
            pos++;

            long length = instance.GetLength(source, ref pos);

            instance.elements.Add(AsnCertificationRequestInfo.Decode(source, ref pos));
            instance.elements.Add(AsnAlgorithmIdentifier.Decode(source, ref pos));
            instance.elements.Add(AsnBitstring.Decode(source, ref pos));

            return(instance);
        }
Ejemplo n.º 3
0
        public static AsnCertificate Decode(byte[] source, ref int pos)
        {
            AsnCertificate instance = new AsnCertificate();

            //instance.CheckContextTag(source, ref pos);
            pos++;

            long len = instance.GetLength(source, ref pos);

            instance.elements.Add(AsnToBeSignedCertificate.Decode(source, ref pos));
            instance.elements.Add(AsnAlgorithmIdentifier.Decode(source, ref pos));
            instance.elements.Add(AsnBitstring.Decode(source, ref pos));

            return(instance);
        }
Ejemplo n.º 4
0
        public static AsnToBeSignedCertificate Decode(byte[] source, ref int pos)
        {
            AsnToBeSignedCertificate instance = new AsnToBeSignedCertificate();

            //instance.CheckContextTag(source, ref pos);
            pos++;

            int len = instance.GetLength(source, ref pos);

            // peek into the next byte to see if we have an explicit tag (should be there)
            if (source[pos] == 0xa0)
            {
                pos++;
                len = instance.GetLength(source, ref pos);
            }

            instance.version       = AsnInteger.Decode(source, ref pos);
            instance.serialNumber  = AsnInteger.Decode(source, ref pos);
            instance.signature     = AsnAlgorithmIdentifier.Decode(source, ref pos);
            instance.issuer        = AsnName.Decode(source, ref pos);
            instance.validity      = AsnValidity.Decode(source, ref pos);
            instance.subject       = AsnName.Decode(source, ref pos);
            instance.subjectPKInfo = AsnPublicKeyInfo.Decode(source, ref pos);

            if (source[pos] == 0xa1)
            {
                pos++;
                instance.GetLength(source, ref pos);
                instance.issuerUniqueID = AsnBitstring.Decode(source, ref pos);
            }
            if (source[pos] == 0xa2)
            {
                pos++;
                instance.GetLength(source, ref pos);
                instance.subjectUniqueID = AsnBitstring.Decode(source, ref pos);
            }
            if (source[pos] == 0xa3)
            {
                pos++;
                instance.GetLength(source, ref pos);
                instance.extensions = AsnExtensions.Decode(source, ref pos);
            }

            return(instance);
        }
Ejemplo n.º 5
0
        public static AsnPrivateKeyInfo Decode(byte[] source, ref int pos)
        {
            AsnPrivateKeyInfo instance = new AsnPrivateKeyInfo();

            //CheckContextTag(source, ref pos);
            pos++;

            int len = instance.GetLength(source, ref pos);

            instance.algorithm = AsnAlgorithmIdentifier.Decode(source, ref pos);
            instance.publicKey = AsnBitstring.Decode(source, ref pos);

            // TODO: further decode publicKey into AsnKeyPair
            int bi = 0;

            instance.keys = AsnPrivateKeyPair.Decode(instance.publicKey.value, ref bi);

            return(instance);
        }
Ejemplo n.º 6
0
 public AsnPrivateKeyInfo()
 {
     algorithm = new AsnAlgorithmIdentifier();
     publicKey = new AsnBitstring();
     keys      = new AsnPrivateKeyPair();
 }