public static void main(String[] args) throws Exception{
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.genKeyPair();
RSAPrivateKey rsaPrivatekey = (RSAPrivateKey)kp.getPrivate();
RSAPublicKey rsaPublickey = (RSAPublicKey)kp.getPublic();
Cipher ci = Cipher.getInstance("RSA");
ci.init(Cipher.ENCRYPT_MODE, rsaPublickey);
String encrypt_str = "www";
byte[] encryt_bytes = ci.doFinal(encrypt_str.getBytes());
Cipher de_ci = Cipher.getInstance("RSA");
ci.init(Cipher.DECRYPT_MODE, rsaPrivatekey);
byte[] decrpt_bytes = ci.doFinal(encryt_bytes);
System.out.println(decrpt_bytes.toString());
}
运行的结果是
为何得不到正确的明文 好像是二进制的BCD码