How to encrypt/decrypt character strings and store them as c

Posted by PeterWokke on 05-Apr-2018 07:17

Dear all,

I would like to encrypt email addresses and store them into database character fields.

When I need the email I have to decrypt the string to its original email address.

Using the encrypt/decrypt functions I get memptr and not character strings.

Using the encrypt function the input can be a character and output is a memptr.

Could try to get the character string out of this memptr to store this character string.

Using the decrypt function the input can be a memptr. So I could put the encrypted character string into it?

Output is a memptr and extract the character out of it. Question will this be the original email address?

Who has some experience with this? Could it work like this?

Regards,

Peter Wokke 

All Replies

Posted by Stefan Drissen on 05-Apr-2018 07:23

base64-encode and base64-decode are your friends:

def var rkey as raw.

def var lcc as longchar.

rkey = generate-random-key.

lcc = base64-encode( encrypt( "my@mail.com", rkey  ) ).

message

  string( lcc )

  decrypt( base64-decode( lcc ), rkey )

view-as alert-box.

Posted by Patrick Tingen on 05-Apr-2018 08:01

Out of curiosity: why?

Posted by Stefan Drissen on 05-Apr-2018 08:17

The tag says it all: GDPR

Posted by PeterWokke on 06-Apr-2018 01:50

Stefan,

Thank you to forward those friends.

I use generate-pbe-key to avoid to store this key in the database as well.

I can message this decrypt( base64-decode( lcc ), rkey ).

But have to convert it back to a character string as email address.

User should be able to adjust when needed.

Have to forward it as character string to PostNL.

If you can help on this I be thankful.

Kind regards,

Peter

Posted by e.schutten on 06-Apr-2018 02:12

Peter,

Just a warning from my side.

Be very careful by using passwords in .R code. They can easily be extracted with a tool like STRINGS from the Windows SysInternalsSuite.

Posted by PeterWokke on 06-Apr-2018 02:13

encryptCharacter.p

define input parameter pcToEncrypt as character no-undo.

define output parameter pcEncrypted as character no-undo.

define variable rKey as raw no-undo.

define variable lcEncoded as longchar no-undo.

rKey = generate-pbe-key("Progress").

lcEncoded = base64-encode( encrypt( pcToEncrypt, rkey  ) ).

pcEncrypted = string(lcEncoded).

Posted by PeterWokke on 06-Apr-2018 02:14

decryptCharacter.p

define input parameter pcToDecrypt as character no-undo.

define output parameter pcDecrypted as character no-undo.

define variable rKey as raw no-undo.

define variable lcEncoded as longchar no-undo.

define variable rEncoded as raw no-undo.

rKey = generate-pbe-key("Progress").

rEncoded = decrypt( base64-decode( pcToDecrypt ), rkey ).

lcEncoded = get-string(rEncoded,1,length(rEncoded)).

pcDecrypted = string(lcEncoded).

Posted by PeterWokke on 06-Apr-2018 02:21

Dear All.

With those two procedures I can use to encrypt and decrypt character strings like emails.

there is another discussion related to this issue:

community.progress.com/.../117081

Still have to work on hiding the key.

Peter

Posted by martinz on 06-Apr-2018 02:38

Hiding the key shouldn't be very difficult. It is essentially a user-secret and should, as such, not reside in your code. Put it in the registry, a file, or somewhere else, but not in the code. Off course you should be able to recreate the key, in case it's lost.

This thread is closed