Skip to content

Commit

Permalink
Access MD5.js directly. Fixes issue #7
Browse files Browse the repository at this point in the history
  • Loading branch information
blafoo committed Jan 13, 2024
1 parent 30238cd commit 7068e8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 388 deletions.
10 changes: 5 additions & 5 deletions src/main/java/de/blafoo/growatt/md5/MD5.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.blafoo.growatt.md5;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.springframework.core.io.ClassPathResource;
import org.openjdk.nashorn.api.scripting.URLReader;

import lombok.extern.slf4j.Slf4j;

Expand All @@ -20,11 +20,11 @@ public static String md5(String password) {
try {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");

engine.eval(new InputStreamReader(new ClassPathResource("/MD5.js").getInputStream()));
engine.eval(new URLReader(new URL("https://server.growatt.com/javaScript/xhb/js/MD5.js?1.0.0")));

Invocable inv = (Invocable) engine;
return (String) inv.invokeFunction("MD5", password);
} catch (NoSuchMethodException | ScriptException | IOException e) {
} catch (NoSuchMethodException | ScriptException | MalformedURLException e) {
log.error(e.getMessage(), e);
}

Expand Down
Loading

0 comments on commit 7068e8e

Please sign in to comment.