Forum: JRuby jruby-openssl : Input format for key and iv

Posted by Gerald Preissler (gadgeteer)
on 2013-02-07 22:33
(Received via mailing list)
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.encrypt
    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

Regards
    Jerry
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.