@Test public void testGenerateKeyPair() throws Exception { RSAUtil.generateKeyPair(1024); }
public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(keySize, new SecureRandom()); KeyPair keyPair = keyPairGen.generateKeyPair(); System.out.println("privateKey:" + keyPair.getPrivate()); System.out.println("publicKey:" + keyPair.getPublic()); return keyPair; }
RSAUtil { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(keySize, new SecureRandom()); KeyPair keyPair = keyPairGen.generateKeyPair(); System.out.println("privateKey:" + keyPair.getPrivate()); System.out.println("publicKey:" + keyPair.getPublic()); return keyPair; } }
RSAUtil { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(keySize, new SecureRandom()); KeyPair keyPair = keyPairGen.generateKeyPair(); System.out.println("privateKey:" + keyPair.getPrivate()); System.out.println("publicKey:" + keyPair.getPublic()); return keyPair; }  }
RSAUtil { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(keySize, new SecureRandom()); KeyPair keyPair = keyPairGen.generateKeyPair(); System.out.println("privateKey:" + keyPair.getPrivate()); System.out.println("publicKey:" + keyPair.getPublic()); return keyPair; }  static KeyPair generateKeyPair(int keySize); static Map<String, String> createKeys(int keySize); static String getPublicKey(KeyPair keyPair); static String getPrivateKey(KeyPair keyPair); static KeyPair getKeyPair(String filePath); static void saveKeyPair(KeyPair kp, String filePath); static String decryptString(String plaintext, String privateKey); static String encryptString(String plaintext, String publicKey); static RSAPublicKey getPublicKey(String publicKey); static RSAPrivateKey getPrivateKey(String privateKey); static String publicEncrypt(String plaintext, RSAPublicKey publicKey); static String privateDecrypt(String plaintext, RSAPrivateKey privateKey); }
RSAUtil { public static KeyPair generateKeyPair(int keySize) throws NoSuchAlgorithmException { KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyPairGen.initialize(keySize, new SecureRandom()); KeyPair keyPair = keyPairGen.generateKeyPair(); System.out.println("privateKey:" + keyPair.getPrivate()); System.out.println("publicKey:" + keyPair.getPublic()); return keyPair; }  static KeyPair generateKeyPair(int keySize); static Map<String, String> createKeys(int keySize); static String getPublicKey(KeyPair keyPair); static String getPrivateKey(KeyPair keyPair); static KeyPair getKeyPair(String filePath); static void saveKeyPair(KeyPair kp, String filePath); static String decryptString(String plaintext, String privateKey); static String encryptString(String plaintext, String publicKey); static RSAPublicKey getPublicKey(String publicKey); static RSAPrivateKey getPrivateKey(String privateKey); static String publicEncrypt(String plaintext, RSAPublicKey publicKey); static String privateDecrypt(String plaintext, RSAPrivateKey privateKey); static final String PUBLIC_KEY; static final String PRIVATE_KEY; static final String CHARSET; static final int KEY_SIZE; }