我想使用PBE加密我的數據。到目前爲止,我寫了下面的代碼:加密:使用基於密碼的加密(PBE)
moteurCryptage = Cipher.getInstance("PBEWithMD5AndDES");
PBEKeySpec spécifClé=new PBEKeySpec(mdp.toCharArray());
SecretKeyFactory usineàClefs=SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey clé=null;
try {
clé = usineàClefs.generateSecret(spécifClé);
} catch (InvalidKeySpecException ex) {
Logger.getLogger(DiskUtilView.class.getName()).log(Level.SEVERE, null, ex);
}
moteurCryptage.init(Cipher.ENCRYPT_MODE,clé);
byte[] paramètresEncodage;
try {
paramètresEncodage=moteurCryptage.getParameters().getEncoded();
} catch (IOException ex) {
paramètresEncodage=null;
}
destination=moteurCryptage.update(source1.getBytes());
destination=moteurCryptage.doFinal(source2.getBytes());
moteurCryptage.init(Cipher.DECRYPT_MODE,clé,paramètresEncodage);
source=new String(moteurCryptage.doFinal(destination));
加密似乎工作(我沒有得到任何錯誤,既不是編譯也不執行期間),但Cipher
對象的解密不接受初始化javax.crypto.SecretKey
類(編譯錯誤)。它反而要求java.security.key
。
我該怎麼辦?
在此先感謝您花費時間來幫助我。
UFF,法國人物很難消除。而且,如果使用英文,變量名將更具可讀性:)。還有一些對我們來說屬於未知類型的變量。請下次嘗試儘可能編譯。 – 2012-03-29 15:34:33