Skip to content
Advertisement

Adapting An Encryption Algorithm Written in Javascript to Java

To summarize my problem, I want to adapt an encryption algorithm written in Javascript to the Java side. The content produced here is used in the header of the service I am calling. But even though I have tried many ways, I have not been able to find the real algorithm yet.

The algorithm written in Javascript is as follows:

JavaScript

The algorithm I tried on the Java side is as follows:

JavaScript

Example output when I try it on the javascript side:

JavaScript

Example output when I try it on the Java side:

JavaScript

The formats do not match each other. By the way, if you need the RFC1123_PATTERN constant;

JavaScript

Advertisement

Answer

encode.toString() returns a String representing the byte[], s. e.g. here, but not, as you probably assume, an ASCII or UTF8 decoding.

For the latter use in the Java code:

JavaScript

or alternatively:

JavaScript

Test:
For the date string Sat, 18 Jun 2022 17:07:55 GMT both codes return the value rSQNB1HOmHEPH982kd9ix0%2F%2F58A%3D.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement