I want to encrypt and decrypt a file in java, i had read this url http://www-users.york.ac.uk/~mal503/lore/pkencryption.htm and i got two files namely public Security certif
Here is the Simplest Piece of Code for encrypting a document with any Key(Here Random Key)
randomKey = randomKey.substring(0, 16);
keyBytes = randomKey.getBytes();
key = new SecretKeySpec(keyBytes, "AES");
paramSpec = new IvParameterSpec(iv);
ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
in = new FileInputStream(srcFile);
out = new FileOutputStream(encryptedFile);
out = new CipherOutputStream(out, ecipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
in.close();
out.flush();
out.close();