Simple Encryption
For storing credit cards of our clients in our databases we use an asymmetric encryption system. Our web server farm only has the public key to encrypt the incoming cc’s. For the actual billing we use an internal server with no direct ties to the net. It receives a list of encrypted credit cards and the amount owed and goes to work with the private key to decrypt the cards and balance the books.
This little class does the encryption and decryption and even allows you to create a valid key pair. The ruby openssl library is not really documented so this might be useful to someone.
require 'key'
Crypto.create_keys # creates rsa_key and rsa_key.pub
priv_key = Crypto::Key.from_file('rsa_key')
pub_key = Crypto::Key.from_file('rsa_key.pub')
text = "I was encrypted but came back!"
secret = pub_key.encrypt(text)
puts priv_key.decrypt(secret) #=>
"I was encrypted but came back!"