Page 1 of 1

svyCrypto AES encryption

PostPosted: Tue Mar 30, 2021 9:18 am
by jdbruijn
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?

Re: svyCrypto AES encryption

PostPosted: Tue Mar 30, 2021 5:15 pm
by sean
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.