Put RSA key into variable

Are you using LiveCode to create server scripts or CGIs?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Put RSA key into variable

Post by ghettocottage » Tue Mar 24, 2015 12:01 am

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?

Peter Wood
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Mon Jul 06, 2009 4:53 am
Location: Bamboo River

Re: Put RSA key into variable

Post by Peter Wood » Thu Apr 09, 2015 2:41 pm

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.

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 278
Joined: Tue Apr 10, 2012 9:18 am

Re: Put RSA key into variable

Post by ghettocottage » Thu Apr 09, 2015 3:21 pm

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.

Post Reply

Return to “CGIs and the Server”