From: Patrick Toomey Date: 2006-09-26T00:20:10+09:00 Subject: Re: cryptography (RSA) On Monday, September 25, 2006, at 09:55AM, Rodrigo Dominguez wrote: >> Hi, >> >> i think that you used the openssl-ruby-bindings in a wrong way. >> First, to set the encryption key, you have to use >> des.key = key (not des.encrypt(key)). >> Second, when using a 128-bit Algorithm, your key must be 128-bit. >> Your key is only 8*7=56 bit. >> Third, the encryption algorithms not only need the same key, they also >> need the same iv (initialisation vector) to show the same results. >> In ruby it is >> des.iv = iv. >> I bet google shows enough examples how to use openssl in ruby the right >> way. >> Hello, I am coming into this conversation in the middle, but a quick googling found the following discussion. http://www.bigbold.com/snippets/posts/show/576 In this thread they talk about ruby openssl expecting the key to come in as a binary data, not a simple string of hex digits. I'll paste a relevant quote from the linked thread... ####BEGIN QUOTE HERE#### " binary_data = unpack('a2'*32).map{|x| x.hex}.pack('c'*32) The "unpack" call assumes you have 32 pairs of hex digits (the 'a2' bit will match a two digit hex number). Change the '32' to match however many hex numbers are in your string. The "map" call creates an array from the unpacked string, with the 32 two-digit hex numbers converted into 32 decimal numbers. The "pack" call takes this array of 32 integers and converts it into a packed stream of 32 bytes." ####END QUOTE HERE#### Hope this helps somewhat. Patrick