我想在此代码上添加一些RSA加密,但是我不知道该怎么做,因为我还是java的新手。
我想在此AES加密中添加RSA加密。
我已经尝试了很多次,但这仍然让我感到困惑。
try {
//get the file to encrypt and set the output
FileInputStream fileIn = new FileInputStream(fileLocation.getText());
FileOutputStream fileOut = new FileOutputStream(path);
//generating the key
KeyGenerator gen = KeyGenerator.getInstance("AES");
gen.init(128);
SecretKey secret = gen.generateKey();
byte[] k = secret.getEncoded();
String text = Base64.getEncoder().encodeToString(k);
SecretKeySpec key = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES");
enc.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(fileOut, enc);
byte[] buf = new byte[1024];
int read;
while((read=fileIn.read(buf))!=-1){
cos.write(buf,0,read);
}
fileIn.close();
fileOut.flush();
cos.close();
JOptionPane.showMessageDialog(null, "Encryption Successfull!");`