Exemplo n.º 1
0
        /**
         * Produce an object suitable for an ASN1OutputStream.
         * <pre>
         * TBSRequest      ::=     SEQUENCE {
         *     version             [0]     EXPLICIT Version DEFAULT v1,
         *     requestorName       [1]     EXPLICIT GeneralName OPTIONAL,
         *     requestList                 SEQUENCE OF Request,
         *     requestExtensions   [2]     EXPLICIT Extensions OPTIONAL }
         * </pre>
         */
        public override ASN1Object toASN1Object()
        {
            ASN1EncodableVector v = new ASN1EncodableVector();

            //
            // if default don't include.
            //
            if (version.getValue().intValue() != 0)
            {
                v.add(new DERTaggedObject(true, 0, version));
            }

            if (requestorName != null)
            {
                v.add(new DERTaggedObject(true, 1, requestorName));
            }

            v.add(requestList);

            if (requestExtensions != null)
            {
                v.add(new DERTaggedObject(true, 2, requestExtensions));
            }

            return(new DERSequence(v));
        }
Exemplo n.º 2
0
        public BigInteger getMaximum()
        {
            if (maximum == null)
            {
                return(null);
            }

            return(maximum.getValue());
        }
Exemplo n.º 3
0
        public BigInteger getAuthorityCertSerialNumber()
        {
            if (certserno != null)
            {
                return(certserno.getValue());
            }

            return(null);
        }
Exemplo n.º 4
0
        public BigInteger getMinimum()
        {
            if (minimum == null)
            {
                return(BigInteger.valueOf(0));
            }

            return(minimum.getValue());
        }
Exemplo n.º 5
0
        public BigInteger getKeyLength()
        {
            if (keyLength != null)
            {
                return(keyLength.getValue());
            }

            return(null);
        }
Exemplo n.º 6
0
        public BigInteger getRC2ParameterVersion()
        {
            if (version == null)
            {
                return(null);
            }

            return(version.getValue());
        }
Exemplo n.º 7
0
        public static AsymmetricKeyParameter CreateKey(SubjectPublicKeyInfo keyInfo)
        {
            AlgorithmIdentifier algId = keyInfo.getAlgorithmId();

            if (algId.getObjectId().Equals(PKCSObjectIdentifiers.rsaEncryption) ||
                algId.getObjectId().Equals(X509ObjectIdentifiers.id_ea_rsa))
            {
                RSAPublicKeyStructure pubKey = new RSAPublicKeyStructure((ASN1Sequence)keyInfo.getPublicKey());

                return(new RSAKeyParameters(false, pubKey.getModulus(), pubKey.getPublicExponent()));
            }
            else if (algId.getObjectId().Equals(PKCSObjectIdentifiers.dhKeyAgreement) ||
                     algId.getObjectId().Equals(X9ObjectIdentifiers.dhpublicnumber))
            {
                DHParameter para = new DHParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger  derY = (DERInteger)keyInfo.getPublicKey();

                return(new DHPublicKeyParameters(derY.getValue(), new DHParameters(para.getP(), para.getG())));
            }
            else if (algId.getObjectId().Equals(OIWObjectIdentifiers.elGamalAlgorithm))
            {
                ElGamalParameter para = new ElGamalParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger       derY = (DERInteger)keyInfo.getPublicKey();

                return(new ElGamalPublicKeyParameters(derY.getValue(), new ElGamalParameters(para.getP(), para.getG())));
            }
            else if (algId.getObjectId().Equals(X9ObjectIdentifiers.id_dsa) ||
                     algId.getObjectId().Equals(OIWObjectIdentifiers.dsaWithSHA1))
            {
                DSAParameter para = new DSAParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger   derY = (DERInteger)keyInfo.getPublicKey();

                return(new DSAPublicKeyParameters(derY.getValue(), new DSAParameters(para.getP(), para.getQ(), para.getG())));
            }
            else if (algId.getObjectId().Equals(X9ObjectIdentifiers.id_ecPublicKey))
            {
                X962Parameters     para    = new X962Parameters((ASN1Object)keyInfo.getAlgorithmId().getParameters());
                ECDomainParameters dParams = null;

                if (para.isNamedCurve())
                {
                    DERObjectIdentifier oid = (DERObjectIdentifier)para.getParameters();
                    X9ECParameters      ecP = X962NamedCurves.getByOID(oid);

                    dParams = new ECDomainParameters(
                        ecP.getCurve(),
                        ecP.getG(),
                        ecP.getN(),
                        ecP.getH(),
                        ecP.getSeed());
                }
                else
                {
                    X9ECParameters ecP = new X9ECParameters((ASN1Sequence)para.getParameters().toASN1Object());


                    dParams = new ECDomainParameters(
                        ecP.getCurve(),
                        ecP.getG(),
                        ecP.getN(),
                        ecP.getH(),
                        ecP.getSeed());
                }

                DERBitString    bits = keyInfo.getPublicKeyData();
                byte[]          data = bits.getBytes();
                ASN1OctetString key  = new DEROctetString(data);

                X9ECPoint derQ = new X9ECPoint(dParams.getCurve(), key);

                return(new ECPublicKeyParameters(derQ.getPoint(), dParams));
            }
            else
            {
                throw new Exception("algorithm identifier in key not recognised");
            }
        }
Exemplo n.º 8
0
 public BigInteger getIterations()
 {
     return(iterations.getValue());
 }
Exemplo n.º 9
0
        public static AsymmetricKeyParameter CreateKey(PrivateKeyInfo keyInfo)
        {
            AlgorithmIdentifier algId = keyInfo.getAlgorithmId();

            if (algId.getObjectId().Equals(PKCSObjectIdentifiers.rsaEncryption))
            {
                RSAPrivateKeyStructure keyStructure = new RSAPrivateKeyStructure((ASN1Sequence)keyInfo.getPrivateKey());
                return(new RSAPrivateCrtKeyParameters(
                           keyStructure.getModulus(),
                           keyStructure.getPublicExponent(),
                           keyStructure.getPrivateExponent(),
                           keyStructure.getPrime1(),
                           keyStructure.getPrime2(),
                           keyStructure.getExponent1(),
                           keyStructure.getExponent2(),
                           keyStructure.getCoefficient()));
            }
            else if (algId.getObjectId().Equals(PKCSObjectIdentifiers.dhKeyAgreement))
            {
                DHParameter para = new DHParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger  derX = (DERInteger)keyInfo.getPrivateKey();
                return(new DHPrivateKeyParameters(derX.getValue(), new DHParameters(para.getP(), para.getG())));
            }
            else if (algId.getObjectId().Equals(OIWObjectIdentifiers.elGamalAlgorithm))
            {
                ElGamalParameter para = new ElGamalParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger       derX = (DERInteger)keyInfo.getPrivateKey();
                return(new ElGamalPrivateKeyParameters(derX.getValue(), new ElGamalParameters(para.getP(), para.getG())));
            }
            else if (algId.getObjectId().Equals(X9ObjectIdentifiers.id_dsa))
            {
                DSAParameter para = new DSAParameter((ASN1Sequence)keyInfo.getAlgorithmId().getParameters());
                DERInteger   derX = (DERInteger)keyInfo.getPrivateKey();
                return(new DSAPrivateKeyParameters(derX.getValue(), new DSAParameters(para.getP(), para.getQ(), para.getG())));
            }
            else if (algId.getObjectId().Equals(X9ObjectIdentifiers.id_ecPublicKey))
            {
                X962Parameters     para    = new X962Parameters((ASN1Object)keyInfo.getAlgorithmId().getParameters());
                ECDomainParameters dParams = null;

                if (para.isNamedCurve())
                {
                    DERObjectIdentifier oid = (DERObjectIdentifier)para.getParameters();
                    X9ECParameters      ecP = X962NamedCurves.getByOID(oid);

                    dParams = new ECDomainParameters(
                        ecP.getCurve(),
                        ecP.getG(),
                        ecP.getN(),
                        ecP.getH(),
                        ecP.getSeed());
                }
                else
                {
                    X9ECParameters ecP = new X9ECParameters(
                        (ASN1Sequence)para.getParameters());
                    dParams = new ECDomainParameters(
                        ecP.getCurve(),
                        ecP.getG(),
                        ecP.getN(),
                        ecP.getH(),
                        ecP.getSeed());
                }

                ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence)keyInfo.getPrivateKey());

                return(new ECPrivateKeyParameters(ec.getKey(), dParams));
            }
            else
            {
                throw new Exception("algorithm identifier in key not recognised");
            }
        }
Exemplo n.º 10
0
 public int getKeyLength()
 {
     return(keyLength.getValue().intValue());
 }
Exemplo n.º 11
0
 public int getVersion()
 {
     return(version.getValue().intValue() + 1);
 }
Exemplo n.º 12
0
 public BigInteger getIterationCount()
 {
     return(iterationCount.getValue());
 }