Miffed… Simple Code, but … org.jasypt.exceptions.EncryptionOperationNotPossibleException

末鹿安然 提交于 2019-12-23 06:31:37

问题


I have used this code or something similar time and again within the server code on my web apps, but now I am trying to make a command line utility to work with the maintenance backend.

Keep on getting a EncryptionOperationNotPossibleException, but can't see what I'm doing wrong in the code. To test the snippet I've used a real encrypted string to make sure it's not the test input.

Anybody out there see where in the code this exception would come from?

import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.util.text.BasicTextEncryptor;

public class decipher {

    /**
     * @param args
     */
    public static void main(String[] args) {
        if (args[0] != null) {
            String encstr = args[0];
            String decstr = "";

            if (encstr != null && !encstr.equals("")) {
                try {
                    BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
                    textEncryptor.setPassword("1234566789");
                    decstr = textEncryptor.decrypt(encstr);
                    System.out.println(decstr);
                } catch (EncryptionOperationNotPossibleException e) {
                    System.out.println(e.toString());
                }
            } else {
                System.out.println("Passed empty string... not decrypted.");
            }
        } else {
            System.out.println("This program requires and encrypted text input.");
        }
    }
}

回答1:


Fixed!! Turns out the input string that I was using was not a valid encrypted string in the first place!! First run your script with encrypt, copy and past a string, then run decrypt against that string...



来源:https://stackoverflow.com/questions/4905281/miffed-simple-code-but-org-jasypt-exceptions-encryptionoperationnotpossi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!