Hello,
I’m trying to encrypt some credit card numbers for later consumption by
a .NET app, and I’m having trouble getting the output to match up…I’m
following the guide from Ola B. here:
http://olabini.com/blog/2008/08/ruby-security-quick-guide/
Long story short, I’m using DES3, my sample app (copied from the above
guide) and its output:
#--------------------------------------------------
require ‘base64’
require ‘openssl’
KEY = “42269702-c1cd-4df1-9df3-”
IV = “01234567”
def encrypt_and_encode(s)
cipher = OpenSSL::Cipher::Cipher.new('des-ede3-cbc')
cipher.encrypt
cipher.key = KEY
cipher.iv = IV
output = ""
output << cipher.update(s)
output << cipher.final
Base64.encode64(output)
end
encoded = encrypt_and_encode(“1234123412341234”)
p encoded
#-----------------------------------------------------
Output is
“kIVlfa8lAV8mh7hF9NcEXAU50k4FfGEH\n” …
If I run its equivalent using openssl from the command line I get:
openssl des3 -in input.txt -out output.txt -K
34323236393730322d633163642d346466312d396466332d -iv 3031323334353637 -a
NPyyxq5SiKvBDxZHf+8nfh0qIm7ynjlT
The .NET side of the code is successfully encrypting/decrypting the same
output as what openssl gives, so I’m guessing there is something I’m
missing with how I’m using jruby-openssl?
Thanks for any insights!
Richard F.