JAVA6のjavascriptエンジンライブラリからスタンフォード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();
}
}