Page 1 of 1

Put RSA key into variable

Posted: Tue Mar 24, 2015 12:01 am
by ghettocottage
I have been playing with encryption using RSA keys. I have generated a key-pair; however, I cannot seem to figure out how to put either of the keys into a variable for using to encrypt and decrypt.

both of the keys are rather long strings...do I need to encode them somehow. Wrapping in quotes does not seem to work.

Any clues?

Re: Put RSA key into variable

Posted: Thu Apr 09, 2015 2:41 pm
by Peter Wood
The LiveCode dictionary says that the keys should be in pem format and shows how to create then using openSSL.

I successfully tried this code:

Code: Select all

#!livecode 

if the environment is "server" and the platform is "MacOS" then 
  set the outputLineEndings to "lf"
  set the outputTextEncoding to "utf8"
end if[code]

put the Version & return

put "See if it works" into tSecret
put URL "binfile:private_key.pem" into tPrivateKey
put URL "binfile:public_key.pem" into tPublicKey
encrypt tSecret using rsa with private key tPrivateKey
put it & return
decrypt it using rsa with public key tPublicKey
put it & return
[/code]

I got these results:

Code: Select all

mbp:LiveCodeServer peter$ ./rsa_test.lc
8.0.0-dp-1
wÃ˚_E
     çI;íµdáäÀ»õˆÎ¢Ëª·Jå.10˘p Ã1îèúeX>¶){N3˚4`
See if it works
Hope this helps.

Re: Put RSA key into variable

Posted: Thu Apr 09, 2015 3:21 pm
by ghettocottage
Thanks for replying.

Since I was getting no responses here, I started another post on a similar topic:

http://forums.livecode.com/viewtopic.php?f=11&t=23812

and had my question answered.