Skip to content

Cipher "des-ede" working differently between JRuby and MRI #931

Closed
@andrenpaes

Description

@andrenpaes

I'm facing a problem trying to decrypt some data using JRuby. I'm using the 'des-ede' cipher with no padding. The code works fine in MRI.

Here's an example:

require 'openssl'
require 'base64'

str = 'helloooo'
key = "WVqcvjGqaD7XBVBlXYbJYw==\n"

%w(des-ede des-ecb des-cbc).each do |cipher_method|
  des = OpenSSL::Cipher::Cipher.new(cipher_method)
  des.encrypt
  des.key = Base64.decode64(key)
  des.padding = 0
  data = des.update(str) + des.final
  enc = Base64.encode64(data)

  des = OpenSSL::Cipher::Cipher.new(cipher_method)
  des.decrypt
  des.key = Base64.decode64(key)
  des.padding = 0
  dec = des.update(Base64.decode64(enc)) + des.final

  puts cipher_method
  puts "'#{str}'"
  puts "'#{enc}'"
  puts "'#{dec}'"
  puts '------------'
end

Here's the output in JRuby (1.7.[3,4]):

$ jruby des-ede_test.rb 
des-ede
'helloooo'
'Nm3bZL1NQug=
'
'helloooo'
------------
des-ecb
'helloooo'
'Nm3bZL1NQug=
'
'helloooo'
------------
des-cbc
'helloooo'
'Nm3bZL1NQug=
'
'helloooo'
------------

Here's the output in MRI (1.9.2-p290 and ruby 1.9.3p327):

des-ede
'helloooo'
'7r9gHRoTpGs=
'
'helloooo'
------------
des-ecb
'helloooo'
'Nm3bZL1NQug=
'
'helloooo'
------------
des-cbc
'helloooo'
'Nm3bZL1NQug=
'
'helloooo'
------------

Is this a problem, or is it not possible to use 'des-ede' on JRuby? It seems weird that des-ede has the same output of des-cbc
Here's the description from 'des-ede' in OpenSSL: Two key triple DES EDE in ECB mode

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions