2011-02-05 24 views
0

我已经使用这个代码或类似的东西一次又一次的服务器代码中对我的web应用程序,但现在我试图让一个命令用于与维护后端一起工作。恼火...简单的代码,但是... org.jasypt.exceptions.EncryptionOperationNotPossibleException

继续得到一个EncryptionOperationNotPossibleException,但不能看到我在代码中做错了什么。为了测试片段,我使用了一个真实的加密字符串来确保它不是测试输入。

在那里的任何人都可以看到代码中的异常来自哪里?

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

回答

2

固定!!发现我使用的输入字符串并不是第一个有效的加密字符串!首先运行你的脚本加密,复制并过去一个字符串,然后运行解密对该字符串...