Encryption/Decryption with RSA public and private keys


This document explains about Encryption/Decryption with public and private keys with simple examples.

Encryption/Decryption is a new functionality in Lucee 5.3. We have new way to encrypt/decrypt string values. First we start with keys. In this case, there are two keys:

  • Private key to encrypt
  • Public key to decrypt

Example 1 :

directory action="list" directory=getDirectoryFromPath(getCurrentTemplatePath()) filter="example*.cfm" name="dir";
loop query=dir {
	echo('<a href="#dir.name#">#dir.name#</a><br>');

This function generates RSA keys. Execute the example code above in the browser and a struct is returned containing the two keys: a private key and a public key. So, we can create these keys, and store them somewhere for later use.

Example 2 :

raw="Hi, Hello !!!";

We now create RSA keys using the GenerateRSAkeys() function, and then use the key to encrypt using the Encrypt() function. The encrypt() function has some arguments. It has key.private which defines the key as the private key, and rsa indicates use of the RSA encryption algorithm. Then run the dump in the browser and we see the encrypted string for your input string.

Example 3 :

raw="Hi, Hello !!!";

This is full detailed example of encrypt/decrypt functions. We create a key and we encrypt with the private key. Then we Decrypt() with the public key. Then run the dump in the browser and we see the original string returned as expected.


Here you can see this details on video also

Encryption/Decryption with public and private keys

See also