Dwolla allows the application to request and store the user's PIN as a pre-authorization form, but requires it to be encrypted. From TOS :
The PIN code must be encrypted during transit and at rest (this includes any and all backup media) using FIPS 140-2 standards (at least)
Typically, I use Bcrypt to encrypt (actually, make a secure hash. Neil Slater, thanks for fixing) something (using the bcrypt-ruby bug), like a password. But if I encrypt using Bcrypt, then I will have to transfer the hash, and of course, this will not match the expected Dwolla, and the PIN will be rejected.
How do you encrypt your PIN and decrypt it for secure receipt?
UPDATE:
One of the answers in the question Andrew refers to below refers to OpenSSL: Cipher , and using this, I can encrypt the PIN code below the code. But the remaining questions:
- How to store a key, iv (initialization vector) and encrypt? Is it safe to save as environment variables, or would it be better to put the database table in a safe hash?
- Is the code below clear for PIN encryption?
- Since I do not have a public key for Dwolla, what is the best way to transfer it?
pin = "1111" # this is what needs to be encrypted
cipher = OpenSSL::Cipher.new('AES-128-CBC')
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
encrypted = cipher.update(pin) + cipher.final
decipher = OpenSSL::Cipher::AES.new(128, :CBC)
decipher.decrypt
decipher.key = key
decipher.iv = iv
plain = decipher.update(encrypted) + decipher.final
puts plain == pin
source
share