我正在尝试从 JAVA6 中的 javascript 引擎库调用 stanford javascript 库加密函数。使用 JAVA6 中的 javascript 引擎库的以下代码,我收到以下错误:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.JavaScriptException: [object Object] (<Unknown source>#19) in <Unknown source> at line number 19
at com.sun.script.javascript.RhinoScriptEngine.invoke(Unknown Source)
at com.sun.script.javascript.RhinoScriptEngine.invokeFunction(Unknown Source)
at Test.main(Test.java:149)
任何帮助将非常感激。
public static void main(String[] args){
try {
ScriptEngineManager mgr = new ScriptEngineManager();
List<ScriptEngineFactory> factories = mgr.getEngineFactories();
System.out.println("Available script engines:");
for (int i = 0; i < factories.size(); i++) {
ScriptEngineFactory factory = factories.get(i);
String engine = factory.getEngineName();
String language = factory.getLanguageName();
System.out.println("-------------------------------------------");
System.out.println("Language: " + language);
System.out.println("Engine: " + engine);
System.out.println("-------------------------------------------");
}
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("ECMAScript");
File script_file = new File("web/js/sjcl.js");
Reader reader = new FileReader(script_file);
engine.eval(reader);
String script = "function decode(encoded_value){"
+ "var decoded_value = sjcl.decrypt('asdf',encoded_value);"
+ "return decoded_value;}"
+ "function encode(plain_text){"
+ "var encoded_value = sjcl.encrypt('asdf', plain_text);"
+ "return encoded_value;}";
engine.eval(script);
Invocable invocableEngine = (Invocable) engine;
String plain_text = "admin";
String cypher_text = (String) invocableEngine.invokeFunction("encode", plain_text);
String plain_text_return = (String)invocableEngine.invokeFunction("decode", cypher_text);
System.out.print("plain_text="+plain_text+"\ncypher_text=" +cypher_text + "\nplain_text_return=" + plain_text_return+"\n");
} catch (Exception e) {
e.printStackTrace();
}
}