when i try to encrypt/decrypt a pdf file using bouncycastle this give me an empty pdf (with 184Ko size). the code works perfectly with text file. But no way with PDF file. any one have an idea how to encrypt/decrypt PDF file in Java ?
bellow the code that i use for encryption, i get an exception when i encrypt a PDF file (java.lang.ArrayIndexOutOfBoundsException: too much data for RSA block) in this line cipherText = cipher.doFinal(input) :
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
byte[] input = acVote;
byte[] cipherText = null;
Cipher cipher = null;
try {
cipher = Cipher.getInstance("RSA/ECB/OAEPPadding", "BC");
SecureRandom random = new SecureRandom();
//do encryption
cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);
cipherText = cipher.doFinal(input);
} catch (Exception ex) {
log.error("Exeption Message : " + ex);
}
When i encrypt a .txt file, it works ...