首页 > java RSA 解密不出来明文

java RSA 解密不出来明文

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码


System.out.println(new String(decrpt_bytes));
【热门文章】
【热门文章】