如何使用空手道解码 Base64 文本

问题描述 投票:0回答:2

我能够在空手道中将纯文本编码为 Base64,但反之亦然。

`def decode =
"""
function(password){
var Base64 = Java.type('java.util.Base64');
byte[] decodedText = Base64.getDecoder().decode(password);
String decodedString = new String(decodedBytes);
return decodedString;
}
"""
def decodedVal = decode(dGVzdGluZw==)
print decodedVal

Error Message in the logs
-unknown-:9 - javascript evaluation failed: function(password){
var Base64 = Java.type('java.util.Base64');
byte[] decodedText = Base64.getDecoder().decode(password);
String decodedString = new String(decodedBytes);
return decodedString;
}, :3:9 Expected an operand but found ]
byte[] decodedText = Base64.getDecoder().decode(password);
^ in at line number 3 at column number 9`

非常感谢任何帮助。

karate
2个回答
0
投票

也许你应该改成这样:

* def decodedVal = decode('dGVzdGluZw==')

但是我看到很多语法错误和错误用法。建议您阅读文档和示例,或者寻求某人的帮助。


0
投票

使用它,它可以解码空手道中的字符串

  * def decoded =
    """
    function decode(secret) {
      var Base64 = Java.type('java.util.Base64');
      var decoded = Base64.getDecoder().decode(secret);
      var String = Java.type('java.lang.String');
      return new String(decoded);
    }
    """
© www.soinside.com 2019 - 2024. All rights reserved.