@Test public void testEncryptString() throws Exception { Map<String, String> keyMap = RSAUtil.createKeys(2048); String privateKey = keyMap.get(RSAUtil.PRIVATE_KEY); System.out.println("私钥：" + privateKey); String publicKey = keyMap.get(RSAUtil.PUBLIC_KEY); System.out.println("公钥：" + publicKey); String encodedData = RSAUtil.encryptString("hello", publicKey); System.out.println("密文：\n" + encodedData); String decodedData = RSAUtil.decryptString(encodedData, privateKey); System.out.println("解密后文字: \r\n" + decodedData); }
public static String encryptString(String plaintext, String publicKey) { if (publicKey == null || plaintext == null) { return null; } return RSAUtil.publicEncrypt(plaintext, RSAUtil.getPublicKey(publicKey)); }
RSAUtil { public static String encryptString(String plaintext, String publicKey) { if (publicKey == null || plaintext == null) { return null; } return RSAUtil.publicEncrypt(plaintext, RSAUtil.getPublicKey(publicKey)); } }
RSAUtil { public static String encryptString(String plaintext, String publicKey) { if (publicKey == null || plaintext == null) { return null; } return RSAUtil.publicEncrypt(plaintext, RSAUtil.getPublicKey(publicKey)); }  }
RSAUtil { public static String encryptString(String plaintext, String publicKey) { if (publicKey == null || plaintext == null) { return null; } return RSAUtil.publicEncrypt(plaintext, RSAUtil.getPublicKey(publicKey)); }  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 String encryptString(String plaintext, String publicKey) { if (publicKey == null || plaintext == null) { return null; } return RSAUtil.publicEncrypt(plaintext, RSAUtil.getPublicKey(publicKey)); }  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; }