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

**URL:** <https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271>\
**Category:** Questions\
**Created:** [July 30, 2024, 8:48am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271 "2024-07-30T08:48:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [July 30, 2024, 8:48am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/1 "2024-07-30T08:48:33Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 30, 2024, 9:14am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/2 "2024-07-30T09:14:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [July 30, 2024, 9:56am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/3 "2024-07-30T09:56:34Z")

</div>

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.

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

```

Best,  
Roland

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 30, 2024, 2:04pm UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/4 "2024-07-30T14:04:18Z")

</div>

Hi Roland,

tested:

```auto
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:

```auto
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));
}

```

---

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [July 30, 2024, 3:55pm UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/5 "2024-07-30T15:55:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 30, 2024, 8:32pm UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/6 "2024-07-30T20:32:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 31, 2024, 6:08am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/7 "2024-07-31T06:08:53Z")

</div>

What happens if you try in both versions

```auto
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.

---

<div class="post-metadata">

**Author:** ![rph](https://avatars.discourse-cdn.com/v4/letter/r/c2a13f/32.png) [@rph](https://forum.servoy.com/u/rph)\
**Post date:** [July 31, 2024, 6:56am UTC](https://forum.servoy.com/t/change-in-algorithm-of-scopes-svycrypto-getsha256/21271/8 "2024-07-31T06:56:10Z")

</div>

Hi Patrick

Thanks for your answer.

> patrick:  
> What happens if you try in both versions
> 
> ```auto
> 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
