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

            pos++;

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

            instance.version         = AsnInteger.Decode(source, ref pos);
            instance.modulus         = AsnInteger.Decode(source, ref pos);
            instance.exponent        = AsnInteger.Decode(source, ref pos);
            instance.privateExponent = AsnInteger.Decode(source, ref pos);
            instance.prime1          = AsnInteger.Decode(source, ref pos);
            instance.prime2          = AsnInteger.Decode(source, ref pos);
            instance.exp1            = AsnInteger.Decode(source, ref pos);
            instance.exp2            = AsnInteger.Decode(source, ref pos);
            instance.coefficient     = AsnInteger.Decode(source, ref pos);

            // bring the parameters into an RSA format
            instance.parameters.Modulus  = instance.modulus.myValue.ToByteArray();
            instance.parameters.Exponent = instance.exponent.myValue.ToByteArray();
            instance.parameters.D        = instance.privateExponent.myValue.ToByteArray();
            instance.parameters.P        = instance.prime1.myValue.ToByteArray();
            instance.parameters.Q        = instance.prime2.myValue.ToByteArray();
            instance.parameters.DP       = instance.exp1.myValue.ToByteArray();
            instance.parameters.DQ       = instance.exp2.myValue.ToByteArray();
            instance.parameters.InverseQ = instance.coefficient.myValue.ToByteArray();

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

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

            // get the sequence length
            long len = instance.GetLength(source, ref pos);

            instance.elements.Add(AsnInteger.Decode(source, ref pos));
            instance.elements.Add(AsnName.Decode(source, ref pos));
            instance.elements.Add(AsnPublicKeyInfo.Decode(source, ref pos));
            instance.elements.Add(AsnAttributes.Decode(source, ref pos));

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

            pos++;

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

            instance.modulus  = AsnInteger.Decode(source, ref pos);
            instance.exponent = AsnInteger.Decode(source, ref pos);

            // bring the parameters into an RSA format
            instance.parameters.Modulus  = instance.modulus.myValue.ToByteArray();
            instance.parameters.Exponent = instance.exponent.myValue.ToByteArray();

            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);
        }