Examples of PKCS10CertificationRequest


Examples of org.bouncycastle.jce.PKCS10CertificationRequest

        {
            generationTest(512, "RSA", "SHA1withRSA", "SunRsaSign");
        }
       
        // elliptic curve GOST A parameter set
        PKCS10CertificationRequest req = new PKCS10CertificationRequest(gost3410EC_A);
        if (!req.verify())
        {
            fail("Failed verify check gost3410EC_A.");
        }

        // elliptic curve GOST B parameter set
        req = new PKCS10CertificationRequest(gost3410EC_B);
        if (!req.verify())
        {
            fail("Failed verify check gost3410EC_B.");
        }

        // elliptic curve GOST C parameter set
        req = new PKCS10CertificationRequest(gost3410EC_C);
        if (!req.verify())
        {
            fail("Failed verify check gost3410EC_C.");
        }
       
        // elliptic curve GOST ExA parameter set
        req = new PKCS10CertificationRequest(gost3410EC_ExA);
        if (!req.verify())
        {
            fail("Failed verify check gost3410EC_ExA.");
        }

        // elliptic curve GOST ExB parameter set
        req = new PKCS10CertificationRequest(gost3410EC_ExB);
        if (!req.verify())
        {
            fail("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());

        KeyPair kp = g.generateKeyPair();

        req = new PKCS10CertificationRequest(
                "ECDSAWITHSHA1", new X509Name("CN=XXX"), kp.getPublic(), null, kp.getPrivate());
        if (!req.verify())
        {
            fail("Failed verify check EC.");
        }
       
        createECRequest("SHA1withECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1);
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

  /**
   * Retrieves the pkcs10 from the encoded data.
   */
  public static PKCS10CertificationRequest getPKCS10(byte[] pkcs10Data) {
    return new PKCS10CertificationRequest(pkcs10Data);
  }
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

        KeyPair rsaKeys = KeyTools.genKeys("512", AlgorithmConstants.KEYALGORITHM_RSA);
        System.out.println("Keys generated.");

        // Generate PKCS10 certificate request
        PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA",
                CertTools.stringToBcX509Name("C=SE,O=AnaTom,CN=HttpTest"), rsaKeys.getPublic(),
                new DERSet(), rsaKeys.getPrivate());
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream dOut = new DEROutputStream(bOut);
        dOut.writeObject(req);
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

            log.info("Using explicit parameter encoding for ECC key.");
            publicKey = ECKeyUtil.publicToExplicitParameters(publicKey, "BC");
        } else {
            log.info("Using named curve parameter encoding for ECC key.");
        }
        final PKCS10CertificationRequest certReq =
            new PKCS10CertificationRequest( sigAlg,
                                            sDN!=null ? new X509Name(sDN) : new X509Name("CN="+alias),
                                            publicKey, new DERSet(),
                                            privateKey,
                                            this.keyStore.getProvider().getName() );
        if ( !certReq.verify() ) {
            String msg = intres.getLocalizedMessage("catoken.errorcertreqverify", alias);
            throw new Exception(msg);
        }
        String filename = alias+".pem";
        final Writer writer = new FileWriter(filename);
        writer.write(CertTools.BEGIN_CERTIFICATE_REQUEST+"\n");
        writer.write(new String(Base64.encode(certReq.getEncoded())));
        writer.write("\n"+CertTools.END_CERTIFICATE_REQUEST+"\n");
        writer.close();
        log.info("Wrote csr to file: "+filename);
    }
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

     */
    private X509Certificate[] storeKey(EjbcaWS ejbcaWS, UserDataVOWS userData, KeyPair keyPair) {
        X509Certificate tmpCert = null;
        final Iterator<X509Certificate> i;
        try {
            final PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name("CN=NOUSED"), keyPair.getPublic(), new DERSet(),
                                                                                     keyPair.getPrivate(), this.privateKeyContainerKeyStore.providerName );
            final CertificateResponse certificateResponse = ejbcaWS.pkcs10Request(userData.getUsername(), userData.getPassword(),
                                                                                  new String(Base64.encode(pkcs10.getEncoded())),null,CertificateHelper.RESPONSETYPE_CERTIFICATE);
            i = (Iterator<X509Certificate>)CertificateFactory.getInstance("X.509").generateCertificates(new ByteArrayInputStream(Base64.decode(certificateResponse.getData()))).iterator();
        } catch (Exception e) {
            m_log.error("Certificate generation problem.", e);
            return null;
        }
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

        vec.add(new DERSet(values));
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(new DERSequence(vec));
        DERSet set = new DERSet(v);
        // Create PKCS#10 certificate request
        PKCS10CertificationRequest p10request = new PKCS10CertificationRequest("SHA1WithRSA",
                CertTools.stringToBcX509Name(dn), keys.getPublic(), set, keys.getPrivate());
        return p10request.getEncoded();       
    }
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

    protected void makeCertRequest(String dn, KeyPair rsaKeys, String reqfile) throws NoSuchAlgorithmException, IOException, NoSuchProviderException,
            InvalidKeyException, SignatureException {
        getLogger().trace(">makeCertRequest: dn='" + dn + "', reqfile='" + reqfile + "'.");

        PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name(dn), rsaKeys.getPublic(), new DERSet(),
                rsaKeys.getPrivate());

        /*
         * We don't use these unnecessary attributes DERConstructedSequence kName
         * = new DERConstructedSequence(); DERConstructedSet kSeq = new
         * DERConstructedSet();
         * kName.addObject(PKCSObjectIdentifiers.pkcs_9_at_emailAddress);
         * kSeq.addObject(new DERIA5String("foo@bar.se"));
         * kName.addObject(kSeq); req.setAttributes(kName);
         */
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream dOut = new DEROutputStream(bOut);
        dOut.writeObject(req);
        dOut.close();

        PKCS10CertificationRequest req2 = new PKCS10CertificationRequest(bOut.toByteArray());
        boolean verify = req2.verify();
        getLogger().info("Verify returned " + verify);

        if (verify == false) {
            getLogger().info("Aborting!");
            return;
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

     keyPair = KeyTools.genKeys("512", null, "RSA");
   }

   public void test01Pkcs10RequestMessage() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException {
     X509Name dn = new X509Name("CN=Test,OU=foo");
     PKCS10CertificationRequest basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     PKCS10RequestMessage msg = new PKCS10RequestMessage(basicpkcs10);
     String username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("C=SE, O=Foo, CN=Test Testsson");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     // oid for unstructuredName, will be handles specially by EJBCA
     dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test + 1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test+1.2.840.113549.1.9.2=AttrValue1 AttrValue2");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     // Completely unknown oid
     dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test + 1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("CN=Test+1.2.840.113549.1.9.3=AttrValue1 AttrValue2");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1 AttrValue2+CN=Test+O=abc");
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);

     dn = new X509Name("1.2.840.113549.1.9.3=AttrValue1\\+\\= AttrValue2+CN=Test+O=abc")// very strange, but should still be valid
     basicpkcs10 = new PKCS10CertificationRequest("SHA1WithRSA", dn,
         keyPair.getPublic(), new DERSet(), keyPair.getPrivate());

     msg = new PKCS10RequestMessage(basicpkcs10);
     username = msg.getUsername();
     assertEquals("Test", username);
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

        }

        DERObject derobj = new ASN1InputStream(new ByteArrayInputStream(decBytes)).readObject();
        if (messageType == ScepRequestMessage.SCEP_TYPE_PKCSREQ) {
            ASN1Sequence seq = (ASN1Sequence) derobj;
            pkcs10 = new PKCS10CertificationRequest(seq);
            if (log.isDebugEnabled()) {
              log.debug("Successfully extracted PKCS10:"+new String(Base64.encode(pkcs10.getEncoded())));
            }
        }
        if (messageType == ScepRequestMessage.SCEP_TYPE_GETCRL) {
View Full Code Here

Examples of org.bouncycastle.jce.PKCS10CertificationRequest

    final byte[] requestBytes = RequestMessageUtils.getDecodedBytes(bytes);
    ret = getCvcDump(false);
    if ((ret == null) && (requestBytes != null) && (requestBytes.length > 0)) {
      // Not a CVC request, perhaps a PKCS10 request
      try {
        final PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest(requestBytes);
//        ret = pkcs10.toString();
        final ASN1InputStream ais = new ASN1InputStream(new ByteArrayInputStream(pkcs10.getEncoded()));
        final DERObject obj = ais.readObject();
        ret = ASN1Dump.dumpAsString(obj);
        type = "PKCS#10";
      } catch (IOException e1) {
         // ignore, move on to certificate decoding
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.