我正在使用JAVA我的朋友使用SYMBIAN
我和我的朋友有相同的rsa模数.如果我使用公钥加密数据,那么我的朋友能够解密相同的数据.但如果我的朋友使用公钥加密数据,那么我无法解密数据.我收到一个错误,因为"数据必须从零开始"
public static byte[] encrypt(byte[] encrptdByte) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] encryptionByte = null;
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
encryptionByte = cipher.doFinal(encrptdByte);
return encryptionByte;
}
public static void decrypt(byte[] encrptdByte) throws NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
byte[] encryptionByte = null;
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, publicKey);
encryptionByte = cipher.doFinal(encrptdByte);
System.out.println("Recovered String ::: " + new String(encryptionByte));
}
Run Code Online (Sandbox Code Playgroud)
谢谢Sunil