Jruby-openssl : Input format for key and iv

We’re trying to exchange encrypted data between a JRuby-based server and
a JavaScript client running in a browser. Right now I’m running into an
issue with the format of the crypto parameters.

When encrypting a string with the following code fragment

cipher = OpenSSL::Cipher.new("AES-128-CBC")
cipher.key    = key
cipher.iv     = iv
encrypted_key = cipher.update(payload) + cipher.final

the API expects the parameters key and iv as Strings. The crypto lib
that is doing the actual encryption (Bouncy Castle) expects these
parameters as byte arrays. Can anyone tell me how the byte array is
constructed from the string input, i.e. in which format do I need to
provide the parameters? Currently I’m using the hex serialization of the
byte array I actually want. This works if I do the en/decryption in
JRuby, but we’re having interop problems with the JavaScript side.

Any hints would be welcome