CFML- und Web-Entwicklung allgemein

Asymmetric Cryptography in ColdFusion Application

I recently needed to encrypt passwords or short text strings with asymmetric cryptography, using two keys, one for encryption and the other for decryption (private and public) in my Coldfusion Application.
RSA provides such algorithms, but Coldfusion only has adequate functions (encrypt, decrypt) with support for symmetric encryption and decryption.

So I googled a while and found this article on 12robots.com which kind of helped me a bit, but I couldn’t get it to work with the current version of BouncyCastle.

Then I just started to build a component with the use of java.security objects, and now it is ready to use with three simple methods.
Create_key_pair returns two keys. Encrypt_string and decrypt_string do what they are built for.

You can download the RSA component from GitHub/ggfx/Coldfusion-rsa.

A quick example:

<cfscript>
	my_string = "my secret";
	obj_rsa = createObject("component","_cfcs.rsa").init();
	keys = obj_rsa.create_key_pair(2048);
	encrypted = obj_rsa.encrypt_string(my_string,keys.public_key);
	decrypted = obj_rsa.decrypt_string(enc,keys.private_key);
</cfscript>

Of course you can save the keys in a file or a database and then reload them when you need to use encrypt_string and decrypt_string.

Nächster in Artikel

Nach oben

© 2017 ggfx.org – golney graphics