svyCrypto AES encryption

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

svyCrypto AES encryption

Postby jdbruijn » Tue Mar 30, 2021 9:18 am

A customer request is to add extra data to a URL to be used by there internal system. Because this data will contain userdata, the request is to encrypt the data for instance using AES. And their system (non-servoy) will then have to decrypt it to be able to use it.
So I've tried using the svyCrypto to encrypt the data, which is easy using the svyCryptoSample. But I run into problems when I try to find an online aes-decryptor that I can use to demonstrate that the encryption is valid.
Here is my encryption code
Code: Select all
       var oCDC = {code="12345678",mail="",phone="003112345678"}
       var algorithm = scopes.svyCrypto.ALGORITHM_NAMES.AES;
       var op = scopes.svyCrypto.createOptions();
       var key = '2lrRKQfHzxACgOG0D1hDDAK3a3b98zfe';
       var cr = scopes.svyCrypto.encrypt(JSON.stringify(oCDC),op)
       var val = cr.getValue();
   var res = scopes.svyCrypto.decryptAsString(val,op);

It seems that svyCrypto uses 192bits keys by default, however, creating a 32chars key should force it to 256bits encryption (it seems to work in the above sample)
But I cannot find an online tool that accepts the encrypted string as input (same when using the default 192bits keys), I have tried the following tools: ... decryption
Any idea's?
Jos de Bruijn
Focus Feedback BV
Servoy Certified Developer
Posts: 488
Joined: Sun Apr 11, 2010 6:34 pm

Re: svyCrypto AES encryption

Postby sean » Tue Mar 30, 2021 5:15 pm

Hi Jos,

I see the issue now. Your key, if string is assumed to be base64-encoded when passed into the svyCrypto API.
However, when I decode your string to bytes, I get length of 24 (192-bit)
Code: Select all
utils.base64ToBytes(key).length // 24

If I just convert your string to raw bytes (NOT assuming it was b64, then I get a 256-bit key)
Code: Select all
var keyBytes = utils.stringToBytes(key); // bytes.length=32

Now if I use that key to encrypt the value, then I can use your online tool to decrypt it and it matches.
Software Engineer
Servoy USA
Posts: 287
Joined: Mon May 21, 2007 6:26 pm
Location: USA

Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 8 guests