Как добавить шифрование RSA на шифрование файла AES? - PullRequest
0 голосов
/ 03 июля 2019

Я хочу добавить шифрование RSA в этот код, но я не знаю, как это сделать, потому что я все еще новичок в Java.

Я хочу добавить шифрование RSA в этом шифровании AES.

Я уже пробовал много раз, но это все еще смущает меня.

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!");`
...