我想使用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