readable encryption result
Sunday, 11 August 2019 · 3 messages · last reply 23 Sep 2019
AB
Andre Bovy11 Aug 2019 09:57 #
Dear all,
I try to make the result of the encryption readable by converting the result either in Base64 or in Hex. Yet I am not able to convert it back to be able to decrypt.
Could you help me ?
André Bovy
let $encrypted := crypto:encrypt('message', 'symmetric','keykeyke','DES’)
let $base64 := string(convert:string-to-base64($encrypted))
let $encrypted := convert:binary-to-string(xs:base64Binary($base64)) (: generates invalid characters :)
return crypto:decrypt($encrypted, 'symmetric','keykeyke','DES')CG
Christian Grün11 Aug 2019 14:57 #
Hi Andre,
The crypt:encrypt function is somewhat broken. As all XQuery strings need to be UTF8-encoded, it would have been correct to return an item of xs:base64Binary (the underlying specification had xs:boolean as actual return type).
Due to this inconsistency, I am actually not sure if there is any proper way to get a readable representation of the result other than writing the file as string to disk and re-read it as binary:
let $encrypted := crypto:encrypt('message', 'symmetric','keykeyke','DES')
return (
file:write-text('tmp', $encrypted),
file:read-binary('tmp')
)I feel that this should be changed with BaseX 9.3. I have opened a new issue [1].
Best,
Christian
[1] https://github.com/BaseXdb/basex/issues/1713
Quoted text · Andre Bovy · 17 lines
On Sun, Aug 11, 2019 at 9:57 AM Andre Bovy <andre.bovy at gmail.com> wrote: > > Dear all, > > I try to make the result of the encryption readable by converting the result either in Base64 or in Hex. > Yet I am not able to convert it back to be able to decrypt. > > Could you help me ? > > André Bovy > > > > let $encrypted := crypto:encrypt('message', 'symmetric','keykeyke','DES’) > let $base64 := string(convert:string-to-base64($encrypted)) > let $encrypted := convert:binary-to-string(xs:base64Binary($base64)) (: generates invalid characters :) > return crypto:decrypt($encrypted, 'symmetric','keykeyke','DES')
CG
Hi André,
The functions of the Cryptographic Module have been updated with the latest snapshot [1]:
crypto:encrypt will now return an item of type xs:base64Binary. In addition, all data and key arguments can now be strings or binary items. Feel free to check out the latest snapshot [2].
Best,
Christian
[1] http://docs.basex.org/wiki/Cryptographic_Module#crypto:decrypt [2] http://files.basex.org/releases/latest/Quoted text · Andre Bovy · 17 lines
On Sun, Aug 11, 2019 at 9:57 AM Andre Bovy <andre.bovy at gmail.com> wrote: > > Dear all, > > I try to make the result of the encryption readable by converting the result either in Base64 or in Hex. > Yet I am not able to convert it back to be able to decrypt. > > Could you help me ? > > André Bovy > > > > let $encrypted := crypto:encrypt('message', 'symmetric','keykeyke','DES’) > let $base64 := string(convert:string-to-base64($encrypted)) > let $encrypted := convert:binary-to-string(xs:base64Binary($base64)) (: generates invalid characters :) > return crypto:decrypt($encrypted, 'symmetric','keykeyke','DES')
Written for BaseX 9.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery