我真的很难解决这个错误:有人可以帮助我吗?
我使用了jasypt标准....请帮助。使用它:http://www.jasypt.org/
ENC : 0Ex+dkccYbqFQOmNrg93pokGkuuWRJ5B
Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:1055)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
at com.billogic.security.Demo.decryptString(Demo.java:17)
at com.billogic.security.Demo.main(Demo.java:24)
我的演示代码?
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
public class Demo {
static StandardPBEStringEncryptor encryptor;
public static String encryptString(String hash){
encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("ABXY");
encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
return encryptor.encrypt(hash);
}
public static String decryptString(String hash){
encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("ABXY");
return encryptor.decrypt(hash);
}
public static void main(String[] args) {
Demo d = new Demo();
String enc = d.encryptString("MyNewString@123");
System.out.println("ENC : "+enc);
String dec = d.decryptString(enc);
System.out.println("DEC : "+dec);
}
}
答案 0 :(得分:1)
解密方法也应该设置算法。
public static String decryptString(String hash){
encryptor = new StandardPBEStringEncryptor();
encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
encryptor.setPassword("ABXY");
return encryptor.decrypt(hash);
}