user5268786
user5268786

Reputation:

Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException

I am really struggling to solve this error: Could anyone please help me?

I used standards of jasypt....Kindly help. Used this : 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)

My Demo code?

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);
    }
}

Upvotes: 1

Views: 4316

Answers (1)

beardedcoder
beardedcoder

Reputation: 26

Decrypt method should set algorithm as well.

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

Upvotes: 1

Related Questions