zoukankan      html  css  js  c++  java
  • 解决shell脚本调用jasypt时的Password is not ASCII错误

    问题场景:使用shell脚本调用jasypt.jar的对一个已加密字串进行解码时报出java.security.spec.InvalidKeySpecException: Password is not ASCII错误。其中加密字串和加密秘钥都是从yaml文件中解析的。以下内容描述了错误处理过程

    问题范围缩小

    在shell中调用jasypt解密的脚本如下:

    java -cp jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="9kQtb2W8i2VmFZIjLt0jPYfjWZLZpPtl" password=shen algorithm=PBEWithMD5AndDES
    

    因为从yaml文件中获取了inputpassword后面所用的变量,并且报错也指明是Password出错,所以使用固定值替换password后面的值,结果加密字串得到正常解密。这样就确定了出错就在password的变量。

    使用od命令查看输入变量的值

    在shell脚本中使用echo ${your_variable} | od -c查看内容中是否有不可见的异常字符。

    echo ${your_variable} | od -c
    0000000        s    h    e    n    
         
    
    0000007
    

    结果发现变量结束除了有正常的换行符 外,还有回车符 。原因是这个yaml文件是其它组在Windows上编写的,其分行都是使用了 的方式,我们在使用shell解析时没有考虑到这种情况。

    最后,使用以下方式解决此问题。

    your_variable_new=$(echo ${your_variable} | tr -d '
    ')
    
  • 相关阅读:
    .net注册iis
    hdu 1081To The Max
    hdu 1312Red and Black
    hdu 1016Prime Ring Problem
    hdu 1159Common Subsequence
    hdu 1372Knight Moves
    hdu 1686Oulipo
    hdu 1241Oil Deposits
    hdu 1171Big Event in HDU
    hdu 4006The kth great number
  • 原文地址:https://www.cnblogs.com/shenfeng/p/shell_jasypt_password_not_ascii.html
Copyright © 2011-2022 走看看