String Manipulation Problems (decoding hex)

First, I’m a java guy. I have a file that contains hex (e.g.
890dfbcb…) and I’m trying to pass that to an OpenSSL::Cipher object as
the key/iv.

For the sake of the question, I’m going to cut the key down in size

In Java I’d do the following (using apache commons codec library)

Hex hex = new Hex() // why these methods aren’t static, i’ll never know
key = “890dfbcb”;
hex.decode(key.getBytes());

(Trying to include as much as possible due to my n00b status)

The value of key.getBytes is
[56, 57, 48, 100, 102, 98, 99, 98]
The value of hex.decode(key.getBytes()) is
[-119, 13, -5, -53]

In ruby:

key.unpack(“H*”)[0] = 3839306466626362
key.hex = 2299395019

When I call
cipher = OpenSSL::Cipher::Cipher.new
key = cipher.random_key

key is a bunch of unicode/binary data.

I’m definitely losing something in the translation here.

key = cipher.random_key

key is a bunch of unicode/binary data.

You seem to be reassigning key?

-r

Roger P. wrote:

You seem to be reassigning key?

I’m using the output of another application (Java) that generates the
key/IV and stores it as hex.

Roger P. wrote:

I’m using the output of another application (Java) that generates the
key/IV and stores it as hex.

http://snippets.dzone.com/posts/show/576
perhaps?

Thanks roger, that got me on the right path but the methods suggested
did not work. Luckily I came across this post which is almost what I
had in the beginning:

http://rubyforge.org/tracker/index.php?func=detail&aid=25756&group_id=4134&atid=15864

basically all I had to do is:

[key].pack(‘H*’)

I’m using the output of another application (Java) that generates the
key/IV and stores it as hex.

http://snippets.dzone.com/posts/show/576
perhaps?