Package org.bouncycastle.jce

Examples of org.bouncycastle.jce.PKCS10CertificationRequest


        return Base64Util.decode(body.replaceAll("\n", ""));
    }

    private static PKCS10CertificationRequest getPKCS10CertificationRequest(String req)
    {
        return new PKCS10CertificationRequest( loadCSR(req) );
    }
View Full Code Here


            throw new IOException(endMarker + " not found");
        }

        try
        {
            return new PKCS10CertificationRequest(Base64.decode(buf.toString()));
        }
        catch (Exception e)
        {
            throw new IOException("problem parsing cert: " + e.toString());
        }
View Full Code Here

        PublicKey pubKey = cert.getPublicKey();

        String signatureAlgorithm = "DSA".equals(pubKey.getAlgorithm()) ? "SHA1withDSA" : "SHA1WITHRSAENCRYPTION";

        PKCS10CertificationRequest csr =
                new PKCS10CertificationRequest(signatureAlgorithm, xname, pubKey, null, privKey);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DEROutputStream deros = new DEROutputStream(baos);
        deros.writeObject(csr.getDERObject());
        String sTmp = new String(org.bouncycastle.util.encoders.Base64.encode(baos.toByteArray()));

        // Header
        sb.append("-----BEGIN NEW CERTIFICATE REQUEST-----\n");
View Full Code Here

            additionalParameters = new HashMap();
        }

        try {
            KeyPair keyPair = generateKeyPair();
            PKCS10CertificationRequest certReq = createCertRequest(keyPair);
            OA4MPResponse mpdsResponse = new OA4MPResponse();
            mpdsResponse.setPrivateKey(keyPair.getPrivate());
            additionalParameters.put(ClientEnvironment.CERT_REQUEST_KEY,
                    Base64.encodeBase64String(certReq.getDEREncoded()));

            if (additionalParameters.get(getEnvironment().getConstants().get(CALLBACK_URI_KEY)) == null) {
                additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), getEnvironment()
                        .getCallback().toString());
            }
View Full Code Here

    PEMReader pemReader = new PEMReader(new StringReader(pemCsr));
    Object pemObject;
    try {
      pemObject = pemReader.readObject();
      if (pemObject instanceof PKCS10CertificationRequest) {
        PKCS10CertificationRequest pkcs10Obj = (PKCS10CertificationRequest) pemObject;
        DefaultCertificate cert = new DefaultCertificate(this);
        cert.setDefaultSerialisation(new PEMSerialisation(cert));
        try {
          cert.setSubjectPublicKey(create(pkcs10Obj.getPublicKey()));
          return cert;
        } catch (NoSuchAlgorithmException e) {
          log.warn("Don't know algorithm required by certification request ", e);
        } catch (NoSuchProviderException e) {
          log.warn("Don't have provider for certification request ", e);
View Full Code Here

        String  endMarker)
        throws IOException
    {
        try
        {
            return new PKCS10CertificationRequest(readBytes(endMarker));
        }
        catch (Exception e)
        {
            throw new PEMException("problem parsing certrequest: " + e.toString(), e);
        }
View Full Code Here

            attrs.put(X509Principal.ST, "Victoria");
            attrs.put(X509Principal.EmailAddress, "feedback-crypto@bouncycastle.org");

            X509Name    subject = new X509Name(attrs);

            PKCS10CertificationRequest req1 = new PKCS10CertificationRequest(
                                                        "SHA1withRSA",
                                                        subject,
                                                        kp.getPublic(),
                                                        null,
                                                        kp.getPrivate());
                               
            byte[]  bytes = req1.getEncoded();

            PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(bytes);

            if (!req2.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check.");
            }

            if (!req2.getPublicKey().equals(req1.getPublicKey()))
            {
                return new SimpleTestResult(false, getName() + ": Failed public key check.");
            }

            // elliptic curve GOST A parameter set
            PKCS10CertificationRequest req = new PKCS10CertificationRequest(gost3410EC_A);
            if (!req.verify())
            {
                System.out.println(new SimpleTestResult(false, getName() + ": Failed verify check gost3410EC_A."));
            }

            // elliptic curve GOST B parameter set
            req = new PKCS10CertificationRequest(gost3410EC_B);
            if (!req.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check gost3410EC_B.");
            }

            // elliptic curve GOST C parameter set
            req = new PKCS10CertificationRequest(gost3410EC_C);
            if (!req.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check gost3410EC_C.");
            }
           
            // elliptic curve GOST ExA parameter set
            req = new PKCS10CertificationRequest(gost3410EC_ExA);
            if (!req.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check gost3410EC_ExA.");
            }

            // elliptic curve GOST ExB parameter set
            req = new PKCS10CertificationRequest(gost3410EC_ExB);
            if (!req.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check gost3410EC_ExA.");
            }
           
            // elliptic curve openSSL
            KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");

            ECCurve curve = new ECCurve.Fp(
                new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
                new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
                new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b

            ECParameterSpec ecSpec = new ECParameterSpec(
                curve,
                curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
                new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n

            g.initialize(ecSpec, new SecureRandom());

            kp = g.generateKeyPair();

            req = new PKCS10CertificationRequest(
                    "ECDSAWITHSHA1", new X509Name("CN=XXX"), kp.getPublic(), null, kp.getPrivate());
            if (!req.verify())
            {
                return new SimpleTestResult(false, getName() + ": Failed verify check EC.");
            }
           
            return new SimpleTestResult(true, getName() + ": Okay");
View Full Code Here

        attrs.put(X509Principal.ST, "Victoria");
        attrs.put(X509Principal.EmailAddress, "feedback-crypto@bouncycastle.org");

        X509Name    subject = new X509Name(attrs);

        PKCS10CertificationRequest req1 = new PKCS10CertificationRequest(
                                                    sigName,
                                                    subject,
                                                    kp.getPublic(),
                                                    null,
                                                    kp.getPrivate(), provider);
                           
        byte[]  bytes = req1.getEncoded();

        PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(bytes);

        if (!req2.verify(provider))
        {
            fail(sigName + ": Failed verify check.");
        }

        if (!req2.getPublicKey(provider).equals(req1.getPublicKey(provider)))
        {
            fail(keyName + ": Failed public key check.");
        }
    }
View Full Code Here

        KeyFactory     fact = KeyFactory.getInstance("ECDSA", "BC");

        privKey = fact.generatePrivate(privKeySpec);
        pubKey = fact.generatePublic(pubKeySpec);

        PKCS10CertificationRequest req = new PKCS10CertificationRequest(
                        algorithm, new X509Name("CN=XXX"), pubKey, null, privKey);
        if (!req.verify())
        {
            fail("Failed verify check EC.");
        }

        req = new PKCS10CertificationRequest(req.getEncoded());
        if (!req.verify())
        {
            fail("Failed verify check EC encoded.");
        }
       
        //
        // try with point compression turned off
        //
        ((ECPointEncoder)pubKey).setPointFormat("UNCOMPRESSED");
       
        req = new PKCS10CertificationRequest(
                        algorithm, new X509Name("CN=XXX"), pubKey, null, privKey);
        if (!req.verify())
        {
            fail("Failed verify check EC uncompressed.");
        }
       
        req = new PKCS10CertificationRequest(req.getEncoded());
        if (!req.verify())
        {
            fail("Failed verify check EC uncompressed encoded.");
        }
       
        if (!req.getSignatureAlgorithm().getObjectId().equals(algOid))
        {
            fail("ECDSA oid incorrect.");
        }
       
        if (req.getSignatureAlgorithm().getParameters() != null)
        {
            fail("ECDSA parameters incorrect.");
        }
       
        Signature sig = Signature.getInstance(algorithm, "BC");
       
        sig.initVerify(pubKey);
       
        sig.update(req.getCertificationRequestInfo().getEncoded());
       
        if (!sig.verify(req.getSignature().getBytes()))
        {
            fail("signature not mapped correctly.");
        }
    }
View Full Code Here

        //
        KeyPair             pair = ecGostKpg.generateKeyPair();
        PrivateKey          privKey = pair.getPrivate();
        PublicKey           pubKey = pair.getPublic();

        PKCS10CertificationRequest req = new PKCS10CertificationRequest(
                        algorithm, new X509Name("CN=XXX"), pubKey, null, privKey);
        if (!req.verify())
        {
            fail("Failed verify check EC.");
        }

        req = new PKCS10CertificationRequest(req.getEncoded());
        if (!req.verify())
        {
            fail("Failed verify check EC encoded.");
        }

        if (!req.getSignatureAlgorithm().getObjectId().equals(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001))
        {
            fail("ECGOST oid incorrect.");
        }

        if (req.getSignatureAlgorithm().getParameters() != null)
        {
            fail("ECGOST parameters incorrect.");
        }

        Signature sig = Signature.getInstance(algorithm, "BC");

        sig.initVerify(pubKey);

        sig.update(req.getCertificationRequestInfo().getEncoded());

        if (!sig.verify(req.getSignature().getBytes()))
        {
            fail("signature not mapped correctly.");
        }
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.jce.PKCS10CertificationRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.