Example #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);
        }
Example #2
0
        public AsnPublicKeyPair()
        {
            RSACryptoServiceProvider prov = new RSACryptoServiceProvider(2048);

            parameters = prov.ExportParameters(false);

            modulus  = new AsnInteger(parameters.Modulus);
            exponent = new AsnInteger(parameters.Exponent);
        }
Example #3
0
        public AsnPrivateKeyPair(int keyLength)
        {
            RSACryptoServiceProvider prov = new RSACryptoServiceProvider(keyLength);

            parameters = prov.ExportParameters(true);

            version         = new AsnInteger(0);
            modulus         = new AsnInteger(parameters.Modulus);
            exponent        = new AsnInteger(parameters.Exponent);
            privateExponent = new AsnInteger(parameters.D);
            prime1          = new AsnInteger(parameters.P);
            prime2          = new AsnInteger(parameters.Q);
            exp1            = new AsnInteger(parameters.DP);
            exp2            = new AsnInteger(parameters.DQ);
            coefficient     = new AsnInteger(parameters.InverseQ);
        }
        public AsnToBeSignedCertificate()
        {
            version = new AsnInteger(2);

            issuer  = new AsnName();
            subject = new AsnName();

            //issuerUniqueID = new AsnBitstring();
            //issuerUniqueID.contextTag = 1;

            //subjectUniqueID = new AsnBitstring();
            //subjectUniqueID.contextTag = 2;

            //extensions = new AsnExtensions();
            //extensions.contextTag = 3;
        }
Example #5
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);
        }
Example #6
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);
        }
        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);
        }
Example #8
0
        public static AsnInteger Decode(byte[] source, ref int pos)
        {
            //CheckContextTag(source, ref pos);
            pos++;

            // length and value in subsequent bytes
            int length = AsnType.GetLength(source, ref pos);

            byte[] raw = new byte[length];
            Array.Copy(source, pos, raw, 0, length);

            AsnInteger instance = new AsnInteger(raw);

            pos += length;

            return(instance);

            //foreach (byte b in value.ToByteArray())
            //{
            //    Console.Write("{0:X2} ", b);
            //}
            //Console.WriteLine(value);
        }