Note, to use a Java class in the JS transformation you’ll need to “type” it.
var Cipher = Java.type("javax.crypto.Cipher");
Cipher.doFinal();
Again, there are two JavaScript languages supported by openHAB.
-
Nashorn: comes with OH by default, the only language supported in the JS Transformation, ECMAScript 5.1 not compatible with node libraries.
-
JS Scripting: needs to be installed (Automation add-on), ECMAScript 2021, can only be used in rules, compatible with many but maybe not all node libraries.
Which one did you use and how? A crypto node library should work with a JS Scripting rule. There can be a lot of reasons why it wouldn’t but most of the things that cause trouble have to do with threading which I wouldn’t expect to happen in a crypto library.
No, but there is an automation add-on that lets you write your Rules in normally written Java. JRule - openHAB Rules using Java
Both Nashorn JavaScript and JS Scripting (which runs on GraalVM) are JS engines running on the JVM. Consequently in addition to implementing core ECMAScript 5.1 and ECMAScript 2021 language features, also have access to all of Java and much of the core openHAB Java classes too. So you can import and use Java Classes in your JavaScript (see the Java.type from above).