我正在尝试编写一个简单的应用程序,它接收上传的文件并在将它们存储到磁盘之前对其进行加密。
这是一个片段
InputStream is = item.openStream(); // item is obtained from file upload iterator
try{
PBEKeySpec keySpec = new PBEKeySpec(passphrase.toCharArray(), salt.getBytes(), iterations, keyLength);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(keySpec); // Throws Exception
CipherInputStream cis;
Cipher cipher = Cipher.getInstance("RSA");
cis = new CipherInputStream(is, cipher);
cipher.init(Cipher.ENCRYPT_MODE, key);
} catch (Exception ex){
// catches the following exceptopn
java.security.spec.InvalidKeySpecException: Inappropriate key specification
at com.sun.crypto.provider.DESedeKeyFactory.engineGenerateSecret(DashoA13*..)
//
}
我也尝试了“RSA/ECB/PKCS1Padding”但没有成功。我做错了什么?