@Test public void testKeyPairGeneration() throws Exception { KeyPair keyPair = TokenUtils.generateKeyPair(2048); PrivateKey privateKey = keyPair.getPrivate(); PublicKey publicKey = keyPair.getPublic(); byte[] privateKeyEnc = privateKey.getEncoded(); byte[] privateKeyPem = Base64.getEncoder().encode(privateKeyEnc); String privateKeyPemStr = new String(privateKeyPem); System.out.println("-----BEGIN RSA PRIVATE KEY-----"); int column = 0; for (int n = 0; n < privateKeyPemStr.length(); n++) { System.out.print(privateKeyPemStr.charAt(n)); column++; if (column == 64) { System.out.println(); column = 0; } } System.out.println("\n-----END RSA PRIVATE KEY-----"); byte[] publicKeyEnc = publicKey.getEncoded(); byte[] publicKeyPem = Base64.getEncoder().encode(publicKeyEnc); String publicKeyPemStr = new String(publicKeyPem); System.out.println("-----BEGIN RSA PUBLIC KEY-----"); column = 0; for (int n = 0; n < publicKeyPemStr.length(); n++) { System.out.print(publicKeyPemStr.charAt(n)); column++; if (column == 64) { System.out.println(); column = 0; } } System.out.println("\n-----END RSA PUBLIC KEY-----"); }
public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); return keyPair; }
TokenUtils { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); return keyPair; } }
TokenUtils { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); return keyPair; } private  TokenUtils(); }
TokenUtils { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); return keyPair; } private  TokenUtils(); static String generateTokenString(String jsonResName); static String generateTokenString(String jsonResName, Set<InvalidClaims> invalidClaims); static String generateTokenString(String jsonResName, Set<InvalidClaims> invalidClaims, Map<String, Long> timeClaims); static PrivateKey readPrivateKey(String pemResName); static PublicKey readPublicKey(String pemResName); static KeyPair generateKeyPair(int keySize); static PrivateKey decodePrivateKey(String pemEncoded); static PublicKey decodePublicKey(String pemEncoded); }
TokenUtils { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); keyPairGenerator.initialize(keySize); KeyPair keyPair = keyPairGenerator.genKeyPair(); return keyPair; } private  TokenUtils(); static String generateTokenString(String jsonResName); static String generateTokenString(String jsonResName, Set<InvalidClaims> invalidClaims); static String generateTokenString(String jsonResName, Set<InvalidClaims> invalidClaims, Map<String, Long> timeClaims); static PrivateKey readPrivateKey(String pemResName); static PublicKey readPublicKey(String pemResName); static KeyPair generateKeyPair(int keySize); static PrivateKey decodePrivateKey(String pemEncoded); static PublicKey decodePublicKey(String pemEncoded);  }