我真的很想解决这个错误:有人可以帮我吗?

我使用了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);
    }
}

最佳答案

解密方法也应设置算法。

public static String decryptString(String hash){
    encryptor = new StandardPBEStringEncryptor();
    encryptor.setAlgorithm("PBEWithMD5AndTripleDES");
    encryptor.setPassword("ABXY");
    return encryptor.decrypt(hash);
}

关于java - 线程“主” org.jasypt.exceptions.EncryptionOperationNotPossibleException中的异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32744642/

10-10 09:20