Change in algorithm of "scopes.svyCrypto.getSHA256"?

Hi

Could anyone please check if I’m only losing my mind or if this ist true:

I’ve executed the following line on a Servoy 2021.3 LTS-Developer and on a “Servoy 2024.03”-Developer and got two different Results:

scopes.svyCrypto.getSHA256("3rzu732rfhndjvdq0rjf3pè£" + "Roland");

On Servoy 2021.03 the result is: “UHhbewb2lJqSdYa3473xkarw1qtq0o51m2QUEkMFLXI=”
On Servoy 2024.03 the result is: “wAOEKyfUEyNEv/QhIE1HS+k7SrvAXBM3XvNRNbuclwE=”

Could anyone confirm this?

Thanks in advance!

Best, Roland

Hi Roland,

I get similar results in both versions.
But real question is which version of the svyUtils module are you using in both versions?

For me this is:
v1.6.1 in Servoy 2021.03
v2024.3.0 in Servoy 2024.03

You can find these version if you click on svyUtils module in solution explorer and look at the properties pane.
The bottom property should say ‘version’

Hope this helps

Hi Marc

Thanks for your reply!

I’ve got exactly the same versions:

v1.6.1 in “Servoy 2021.03”
v2024.3.0 in “Servoy 2024.03”

I’ve found out that it seems to work as long as I just use ASCII-Characters as arguments. But as soon as I have something non ASCII (like for example “é” or “£” (Pound-Sign), the result is completely different!

So it’s really crucial to test it excactly.

scopes.svyCrypto.getSHA256("£"); // results in "tP4VHkE0RTV7HAk1588EpClJLr0j3GK/rbL4mMQxwf0=" (Servoy 2021.3) / results in "bZD7rMBz7gtMQ/OjKRzs2jN2T21m0UIkrWD0cfLIM0s=" (Servoy 2024.3)

Best,
Roland

Hi Roland,

tested:

scopes.svyCrypto.getSHA256("£");

Both versions return the ‘tP4VH…’ result.

Although version numbers look the same it maybe interesting to compare the getHash function in svyCrypto v1.6.1:

function getHash(value, algorithm) {
	/** @type {Array<byte>} */
	var bytes = value instanceof String ? string2Bytes(value) : value;
	var digest = Packages.java.security.MessageDigest.getInstance(algorithm);
	return utils.bytesToBase64(digest.digest(bytes));
}

Hi Marc

Thanks again for your inputs.

I debug through that “getHash”-Function and found a difference in the Byte-Array that is returned by the “string2Bytes”-function. When I have a look at the “string2Bytes”-function in “svyCrypto”, there is a little difference, but more like a clean up of code and not something that really makes any difference. The only thing I could imagine is, that we have Java 11.0.5 for the 2021.03-Servoy and for the 2024.03 it is the built-in Java that is delivered with the developer (in the admin console it says Java 21). In the string2Bytes-function there is only a call “return new java.lang.String(str).getBytes();”. So maybe this has to do with the Java-version? Or a configuration on the Servoy-Admin-Page that I’m not aware?

Best,
Roland

Hi Roland,

very strange, my Java versions are also 11.something and built-in 21 for v2024.3

I’m out of options what could be wrong here.

What happens if you try in both versions

return new java.lang.String(str).getBytes('UTF-8');

Not sure what could have changed on Java’s side, but to me that looks safer in any case.

Hi Patrick

Thanks for your answer.

patrick:
What happens if you try in both versions

return new java.lang.String(str).getBytes('UTF-8');

This is it. If I change it like this in the 2021-developer than I get the same byte-array (and as a result the same hash). Or if I change in the 2024-developer to "return new java.lang.String(str).getBytes(‘cp1252’); then I get also the same hash in both developers (but of course a different one than the ‘UTF-8’-version).

So, obiously somehow the default encoding changed from one developer to the other. But I’ve only found some settings under “Preferences” => “General” (‘Workspace’, but this is for both devlopers already on “other: UTF-8” and then some entries under “Content Types”. I’m not sure which one is relevant for that.

But I remember that when I’ve upgraded from 2021.03 to 2024.03 that there were some new setting-files like “svyBase/.settings/org.eclipse.core.resources.prefs” that have stuff like “encoding/=UTF-8” in there and I’ve wondered what these file are. Maybe these files has something to do with it.

At least I see a solution for my problem, even if I’m a littlebit uncertain what the right fix for this is. Obiously Marc already has the right settings for that because he has the right hashes from beginning. So there seems to be a solution without to adjust the code in “svyCrypto”!

Thanks a lot to Marc and Patrick for your efforts! That really helped me a lot.

Best, Roland