I want to encrypt and decrypt a file in java, I read this url http://www-users.york.ac.uk/~mal503/lore/pkencryption.htm , and I have two files, namely: public Security certificate and private security certificate file and private.pem file, I copied these files and pasted them into the current directory and worte java code as follows, when I run it, encryption or decryption is not performed, see this and tell me where I made a mistake
Encrypt code
File ecryptfile=new File("encrypt data"); File publickeydata=new File("/publickey"); File encryptmyfile=new File("/sys_data.db"); File copycontent =new File("Copy Data"); secure.makeKey(); secure.saveKey(ecryptfile, publickeydata); secure.encrypt(encryptmyfile, copycontent);
Decrypt Code
File ecryptfile=new File("encrypt data"); File privateKeyFile=new File("/privatekey"); File encryptmyfile=new File("/sys_data.db"); File unencryptedFile =new File("unencryptedFile"); try { secure.loadKey(encryptmyfile, privateKeyFile); secure.decrypt(encryptmyfile, unencryptedFile); } catch (GeneralSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
source share