문제

I'm writing a program in Java that requires strings to be encrypted and decrypted. I'm using BasicTextEnctyptor from Jasypt. This is a complex application - using asynchronous networking and things like that. The encryption is between the server and the client. But every time I run both I eventually get a org.jasypt.exceptions.EncryptionOperationNotPossibleException. Because of this application's complexity, I tried to make a simple class:

import org.jasypt.util.text.BasicTextEncryptor;

public class test {
    public static void main(String[] args) {
        String text = "LEMONS";
        String key = "keykeykey";
        BasicTextEncryptor encryptor = new BasicTextEncryptor();
        encryptor.setPassword(key);
        String encrypted = encryptor.encrypt(text);
        System.out.println(encrypted);
        encrypted = encryptor.decrypt(text);
        System.out.println(encrypted);
    }
}

Here's the stack trace of the exception it causes:

6rn3OyR9zsfmd4OfnskSEQ==
Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:918)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
at org.jasypt.util.text.BasicTextEncryptor.decrypt(BasicTextEncryptor.java:112)
at test.main(test.java:11)

So... What's happening here? The basic encryption should be working just fine. I feel like if this is fixed, then the problem in the main application can be fixed in the same way.

도움이 되었습니까?

해결책

encrypted = encryptor.decrypt(text);

since text is your clear text, there is nothing to decrypt ... the exception says just that ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top