Encryption with Ruby 
The code below simply works… all I had to do was install the EzCrypto Ruby gem.
How much work would it have been to accomplish the same three symmetric encryption methods in Java using the JCE? :)
encrypter_test.rb
require 'test/unit'
require 'encrypter'class EncrypterTest < Test::Unit::TestCase
def test_encrypt_aes_128
encrypted = Encrypter.new.encrypt_with_aes_128("private stuff")
assert_equal("\355\317\242F\202*\230V^\333\320M\f\231\210\201", encrypted)
end
def test_encrypt_blowfish
encrypted = Encrypter.new.encrypt_with_blowfish("private stuff")
assert_equal("\241g\266\261\342\020\376Va\006~\004\346\252H\225", encrypted)
end
def test_encrypt_desede
encrypted = Encrypter.new.encrypt_with_desede("private stuff")
assert_equal("\367\326\276\353c}t\301\267A\340\027\227\356fK", encrypted)
end
end
encrypter.rb
require 'rubygems'
require 'ezcrypto'class Encrypter
@@secret_key = "rubyw4y"
@@salt = "1981"
def encrypt_with_aes_128(plainText)
crypto_key = EzCrypto::Key.with_password(@@secret_key, @@salt) # default algorithm is AES 128
cipher_text = crypto_key.encrypt(plainText);
end
def encrypt_with_blowfish(plainText)
crypto_key = EzCrypto::Key.with_password(@@secret_key, @@salt, :algorithm=>'blowfish')
cipher_text = crypto_key.encrypt(plainText);
end
def encrypt_with_desede(plainText)
crypto_key = EzCrypto::Key.with_password(@@secret_key, @@salt, :algorithm=>'des3')
cipher_text = crypto_key.encrypt(plainText);
end
endIt is worth mentioning that this piggy backs off of OpenSSL for the algorithm implementations.
If you're interested in more info check out
http://ezcrypto.rubyforge.org .