Search in sources :

Example 1 with DERInteger

use of org.bouncycastle.asn1.DERInteger in project robovm by robovm.

the class JCEDHPublicKey method isPKCSParam.

private boolean isPKCSParam(ASN1Sequence seq) {
    if (seq.size() == 2) {
        return true;
    }
    if (seq.size() > 3) {
        return false;
    }
    DERInteger l = DERInteger.getInstance(seq.getObjectAt(2));
    DERInteger p = DERInteger.getInstance(seq.getObjectAt(0));
    if (l.getValue().compareTo(BigInteger.valueOf(p.getValue().bitLength())) > 0) {
        return false;
    }
    return true;
}
Also used : DERInteger(org.bouncycastle.asn1.DERInteger)

Example 2 with DERInteger

use of org.bouncycastle.asn1.DERInteger in project robovm by robovm.

the class JCEECPrivateKey method populateFromPrivKeyInfo.

private void populateFromPrivKeyInfo(PrivateKeyInfo info) throws IOException {
    X962Parameters params = new X962Parameters((ASN1Primitive) info.getPrivateKeyAlgorithm().getParameters());
    if (params.isNamedCurve()) {
        ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());
        X9ECParameters ecP = ECUtil.getNamedCurveByOid(oid);
        // BEGIN android-removed
        // if (ecP == null) // GOST Curve
        // {
        //     ECDomainParameters gParam = ECGOST3410NamedCurves.getByOID(oid);
        //     EllipticCurve ellipticCurve = EC5Util.convertCurve(gParam.getCurve(), gParam.getSeed());
        //
        //     ecSpec = new ECNamedCurveSpec(
        //             ECGOST3410NamedCurves.getName(oid),
        //             ellipticCurve,
        //             new ECPoint(
        //                     gParam.getG().getX().toBigInteger(),
        //                     gParam.getG().getY().toBigInteger()),
        //             gParam.getN(),
        //             gParam.getH());
        // }
        // else
        // END android-removed
        {
            EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
            ecSpec = new ECNamedCurveSpec(ECUtil.getCurveName(oid), ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH());
        }
    } else if (params.isImplicitlyCA()) {
        ecSpec = null;
    } else {
        X9ECParameters ecP = X9ECParameters.getInstance(params.getParameters());
        EllipticCurve ellipticCurve = EC5Util.convertCurve(ecP.getCurve(), ecP.getSeed());
        this.ecSpec = new ECParameterSpec(ellipticCurve, new ECPoint(ecP.getG().getX().toBigInteger(), ecP.getG().getY().toBigInteger()), ecP.getN(), ecP.getH().intValue());
    }
    ASN1Encodable privKey = info.parsePrivateKey();
    if (privKey instanceof DERInteger) {
        DERInteger derD = DERInteger.getInstance(privKey);
        this.d = derD.getValue();
    } else {
        ECPrivateKeyStructure ec = new ECPrivateKeyStructure((ASN1Sequence) privKey);
        this.d = ec.getKey();
        this.publicKey = ec.getPublicKey();
    }
}
Also used : X962Parameters(org.bouncycastle.asn1.x9.X962Parameters) X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ECPrivateKeyStructure(org.bouncycastle.asn1.sec.ECPrivateKeyStructure) ECPoint(java.security.spec.ECPoint) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) ECNamedCurveSpec(org.bouncycastle.jce.spec.ECNamedCurveSpec) DERInteger(org.bouncycastle.asn1.DERInteger)

Example 3 with DERInteger

use of org.bouncycastle.asn1.DERInteger in project XobotOS by xamarin.

the class RSAPublicKeyStructure method toASN1Object.

/**
     * This outputs the key in PKCS1v2 format.
     * <pre>
     *      RSAPublicKey ::= SEQUENCE {
     *                          modulus INTEGER, -- n
     *                          publicExponent INTEGER, -- e
     *                      }
     * </pre>
     * <p>
     */
public DERObject toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new DERInteger(getModulus()));
    v.add(new DERInteger(getPublicExponent()));
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DERInteger(org.bouncycastle.asn1.DERInteger)

Example 4 with DERInteger

use of org.bouncycastle.asn1.DERInteger in project XobotOS by xamarin.

the class PKIXCertPath method getEncoded.

/**
     * Returns the encoded form of this certification path, using
     * the specified encoding.
     *
     * @param encoding the name of the encoding to use
     * @return the encoded bytes
     * @exception CertificateEncodingException if an encoding error
     * occurs or the encoding requested is not supported
     *
     **/
public byte[] getEncoded(String encoding) throws CertificateEncodingException {
    if (encoding.equalsIgnoreCase("PkiPath")) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        ListIterator iter = certificates.listIterator(certificates.size());
        while (iter.hasPrevious()) {
            v.add(toASN1Object((X509Certificate) iter.previous()));
        }
        return toDEREncoded(new DERSequence(v));
    } else if (encoding.equalsIgnoreCase("PKCS7")) {
        ContentInfo encInfo = new ContentInfo(PKCSObjectIdentifiers.data, null);
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (int i = 0; i != certificates.size(); i++) {
            v.add(toASN1Object((X509Certificate) certificates.get(i)));
        }
        SignedData sd = new SignedData(new DERInteger(1), new DERSet(), encInfo, new DERSet(v), null, new DERSet());
        return toDEREncoded(new ContentInfo(PKCSObjectIdentifiers.signedData, sd));
    } else // BEGIN android-removed
    // else if (encoding.equalsIgnoreCase("PEM"))
    // {
    //     ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    //     PEMWriter             pWrt = new PEMWriter(new OutputStreamWriter(bOut));
    //
    //     try
    //     {
    //         for (int i = 0; i != certificates.size(); i++)
    //         {
    //             pWrt.writeObject(certificates.get(i));
    //         }
    //     
    //         pWrt.close();
    //     }
    //     catch (Exception e)
    //     {
    //         throw new CertificateEncodingException("can't encode certificate for PEM encoded path");
    //     }
    //
    //     return bOut.toByteArray();
    // }
    // END android-removed
    {
        throw new CertificateEncodingException("unsupported encoding: " + encoding);
    }
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) SignedData(org.bouncycastle.asn1.pkcs.SignedData) ContentInfo(org.bouncycastle.asn1.pkcs.ContentInfo) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) CertificateEncodingException(java.security.cert.CertificateEncodingException) ListIterator(java.util.ListIterator) DERSet(org.bouncycastle.asn1.DERSet) X509Certificate(java.security.cert.X509Certificate) DERInteger(org.bouncycastle.asn1.DERInteger)

Example 5 with DERInteger

use of org.bouncycastle.asn1.DERInteger in project XobotOS by xamarin.

the class JCEDHPublicKey method isPKCSParam.

private boolean isPKCSParam(ASN1Sequence seq) {
    if (seq.size() == 2) {
        return true;
    }
    if (seq.size() > 3) {
        return false;
    }
    DERInteger l = DERInteger.getInstance(seq.getObjectAt(2));
    DERInteger p = DERInteger.getInstance(seq.getObjectAt(0));
    if (l.getValue().compareTo(BigInteger.valueOf(p.getValue().bitLength())) > 0) {
        return false;
    }
    return true;
}
Also used : DERInteger(org.bouncycastle.asn1.DERInteger)

Aggregations

DERInteger (org.bouncycastle.asn1.DERInteger)23 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)10 DERSequence (org.bouncycastle.asn1.DERSequence)9 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1InputStream (com.android.org.bouncycastle.asn1.ASN1InputStream)5 ASN1Integer (com.android.org.bouncycastle.asn1.ASN1Integer)5 ASN1ObjectIdentifier (com.android.org.bouncycastle.asn1.ASN1ObjectIdentifier)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5 DERInteger (com.android.org.bouncycastle.asn1.DERInteger)5 DERSequence (com.android.org.bouncycastle.asn1.DERSequence)5 AlgorithmIdentifier (com.android.org.bouncycastle.asn1.x509.AlgorithmIdentifier)5 TBSCertificate (com.android.org.bouncycastle.asn1.x509.TBSCertificate)5 Time (com.android.org.bouncycastle.asn1.x509.Time)5 V3TBSCertificateGenerator (com.android.org.bouncycastle.asn1.x509.V3TBSCertificateGenerator)5 X509Principal (com.android.org.bouncycastle.jce.X509Principal)5 X509CertificateObject (com.android.org.bouncycastle.jce.provider.X509CertificateObject)5 IOException (java.io.IOException)5 BigInteger (java.math.BigInteger)5 ProviderException (java.security.ProviderException)5 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)5