- public static KeyPair generateKeypair() throws GeneralSecurityException {
- KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
- kpg.initialize(4096);
- return kpg.generateKeyPair();
- }
-
- public static String generatePEMCSR(KeyPair kp, String dn) throws GeneralSecurityException, IOException {
- return generatePEMCSR(kp, dn, new PKCS10Attributes());
- }
-
- public static String generatePEMCSR(KeyPair kp, String dn, PKCS10Attributes atts) throws GeneralSecurityException, IOException {
- return generatePEMCSR(kp, dn, atts, "SHA256WithRSA");
- }
-
- public static String generatePEMCSR(KeyPair kp, String dn, PKCS10Attributes atts, String signature) throws GeneralSecurityException, IOException {
- PKCS10 p10 = new PKCS10(kp.getPublic(), atts);
- Signature s = Signature.getInstance(signature);
- s.initSign(kp.getPrivate());
- p10.encodeAndSign(new X500Name(dn), s);
- return PEM.encode("CERTIFICATE REQUEST", p10.getEncoded());
- }
-