This Win32-based CFX_RSA brings you the best mechanism to communicate in a secure way: You don't have to provide your peer with the only encryption key ... you create a key ring first, containing your private key and your public key. The public key you may - even must - give to all your possible communication peers. Then, they can send messages to you. You get the public keys from your peers to be able to send encrypted stuff to them.
This CFX makes it easy to use this powerful cipher in the Coldfusion arena.
The following rsa_test.cfm is also included in the retail zip.
This is also the example that you see in the example link.
Be aware that this example page takes about 20 seconds to load, because it generates two key rings. So, please be patient.
<html> <head> <title>MindPower - RSA Demo</title> </head>
<body bgcolor="silver">
<cfset source = "The world is beautiful and needs caring by its children">
<cfoutput>
<br>
Source is "#source#" (##chars #Len(source)#)<br><br>
<h1>RSA over string</h1>
<p>RSA is an asymetric cipher. This means, you have to create a keyring with a private and a public key first before you can use this cipher.</p>
<p>Key generation takes time: Take this into accout if you let users create keys online ... to prevent ColdFusion "slow page" timeout.</p>
<p>Currently supported key sizes: 512 bits, 1024 bits, or 2048 bits.</p>
<p>On an AMD Athlon 1.2 GHz it takes about 2-5 secs for 512 bits, about 5-15 secs for 1024 bits and 40-70 secs for 2048 bits. Those times depend on the algorihtm chosen to generate the seeds for the key generation.</p>
<p>The public key of the key ring MUST be made available to all peers which you want to communicate with.</p>
<p>You NEVER give away your private key under no circumstances.</p>
<p>To encrypt something for your peer, you have to encrypt the source with the peer's public key.</p>
<p>To decrypt something from your peer, you have to decrypt the source with your private key.</p>
<h2>Generate YOUR key ring with 512 bits keylength and test it</h2> <cfx_rsa action="generate_key_pair" key_size="512" private_key="yourprivkey" public_key="yourpubkey" debug>
<hr> YOUR.private key: #yourprivkey# (##chars #Len(yourprivkey)#)<br> <hr> YOUR.public key: #yourpubkey# (##chars #Len(yourpubkey)#)<br> <hr>
<cfx_rsa action="encrypt" source="#source#" result="res" public_key="#yourpubkey#"> YOUR.encryption: #res# (##chars #Len(res)#)<br>
<cfx_rsa action="decrypt" source="#res#" result="res2" private_key="#yourprivkey#"> YOUR.decryption: #res2# (##chars #Len(res2)#)<br>
<h2>Generate PEER key ring with 1024 bits keylength and test it</h2> <cfx_rsa action="generate_key_pair" key_size="1024" private_key="peerprivkey" public_key="peerpubkey" debug>
<hr> PEER.private key: #peerprivkey# (##chars #Len(peerprivkey)#)<br> <hr> PEER.public key: #peerpubkey# (##chars #Len(peerpubkey)#)<br> <hr>
<cfx_rsa action="encrypt" source="#source#" result="res" public_key="#peerpubkey#"> PEER.encryption: #res# (##chars #Len(res)#)<br>
<cfx_rsa action="decrypt" source="#res#" result="res2" private_key="#peerprivkey#"> PEER.decryption: #res2# (##chars #Len(res2)#)<br>
<br> <hr> <br>
<h2>YOUR Message to PEER</h2>
<cfset source = "Hi Peer. If you can read this, RSA works as it should">
<cfx_rsa action="encrypt" source="#source#" result="res" public_key="#peerpubkey#"> YOUR.encryption to PEER: #res# (##chars #Len(res)#)<br>
<cfx_rsa action="decrypt" source="#res#" result="res2" private_key="#peerprivkey#"> PEER.decryption from YOU: #res2# (##chars #Len(res2)#)<br>
<h2>PEER'S Message to YOU</h2>
<cfset source = "Hi you. Great, now, we can exchange keys for a symmetric and fast encryption">
<cfx_rsa action="encrypt" source="#source#" result="res" public_key="#yourpubkey#"> PEER.encryption to YOU: #res# (##chars #Len(res)#)<br>
<cfx_rsa action="decrypt" source="#res#" result="res2" private_key="#yourprivkey#"> YOUR.decryption from PEER: #res2# (##chars #Len(res2)#)<br>
</cfoutput>
</body> </html>
|