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="jan.jansen@example.com",phone="003112345678"}
       var algorithm = scopes.svyCrypto.ALGORITHM_NAMES.AES;
       var op = scopes.svyCrypto.createOptions();
       op.setAlgorithmName(algorithm);
       var key = '2lrRKQfHzxACgOG0D1hDDAK3a3b98zfe';
       application.output(key);
       op.setKey(key);
       var cr = scopes.svyCrypto.encrypt(JSON.stringify(oCDC),op)
       var val = cr.getValue();
       application.output(val);
   var res = scopes.svyCrypto.decryptAsString(val,op);
   application.output(res)

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:
https://www.javainuse.com/aesgenerator
https://www.devglan.com/online-tools/ae ... decryption
https://encode-decode.com/aes-256-cbc-encrypt-online/
Any idea's?
Jos de Bruijn
Focus Feedback BV
Servoy Certified Developer
Image
jdbruijn
 
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
op.setKey(keyBytes);
...

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
sean
 
Posts: 289
Joined: Mon May 21, 2007 6:26 pm
Location: USA


Return to Programming with Servoy

Who is online

Users browsing this forum: Bing [Bot] and 5 guests