Search in sources :

Example 6 with KeyPairGenerator

use of org.mozilla.jss.crypto.KeyPairGenerator in project jss by dogtagpki.

the class X509CertTest method testRSA.

public static void testRSA(CryptoToken token, Date notBefore, Date notAfter) throws Exception {
    X509CertImpl certImpl = null;
    X509CertInfo certInfo = null;
    KeyPairGenerator gen = token.getKeyPairGenerator(KeyPairAlgorithm.RSA);
    gen.initialize(4096);
    KeyPair keypairCA = gen.genKeyPair();
    testKeys(keypairCA);
    PublicKey pubCA = keypairCA.getPublic();
    gen.initialize(4096);
    KeyPair keypairUser = gen.genKeyPair();
    testKeys(keypairUser);
    PublicKey pubUser = keypairUser.getPublic();
    CertificateIssuerName issuernameObj = new CertificateIssuerName(new X500Name(issuerDN));
    certInfo = createX509CertInfo(convertPublicKeyToX509Key(pubUser), BigInteger.valueOf(1), issuernameObj, subjectDN, notBefore, notAfter, "SHA256withRSA");
    certImpl = new X509CertImpl(certInfo);
    certImpl.sign(keypairCA.getPrivate(), "SHA256withRSA");
    String certOutput = certImpl.toString();
    System.out.println("Test certificate output: \n" + certOutput);
}
Also used : KeyPair(java.security.KeyPair) X509CertInfo(org.mozilla.jss.netscape.security.x509.X509CertInfo) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKey(java.security.PublicKey) ECPublicKey(java.security.interfaces.ECPublicKey) PK11ECPublicKey(org.mozilla.jss.pkcs11.PK11ECPublicKey) X509CertImpl(org.mozilla.jss.netscape.security.x509.X509CertImpl) CertificateIssuerName(org.mozilla.jss.netscape.security.x509.CertificateIssuerName) KeyPairGenerator(org.mozilla.jss.crypto.KeyPairGenerator) X500Name(org.mozilla.jss.netscape.security.x509.X500Name)

Aggregations

KeyPair (java.security.KeyPair)6 KeyPairGenerator (org.mozilla.jss.crypto.KeyPairGenerator)6 CryptoManager (org.mozilla.jss.CryptoManager)4 CryptoToken (org.mozilla.jss.crypto.CryptoToken)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 PublicKey (java.security.PublicKey)3 TokenException (org.mozilla.jss.crypto.TokenException)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InvalidKeyException (java.security.InvalidKeyException)2 SignatureException (java.security.SignatureException)2 CertificateException (java.security.cert.CertificateException)2 ECPublicKey (java.security.interfaces.ECPublicKey)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 NotInitializedException (org.mozilla.jss.NotInitializedException)2 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)2 InvalidKeyFormatException (org.mozilla.jss.crypto.InvalidKeyFormatException)2 CertificateIssuerName (org.mozilla.jss.netscape.security.x509.CertificateIssuerName)2