# Issue with Jopenssl

**URL:** <https://www.ruby-forum.com/t/issue-with-jopenssl/176459>\
**Category:** JRuby\
**Created:** [September 30, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/issue-with-jopenssl/176459 "2009-09-30T21:51:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lodi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@lodi](https://www.ruby-forum.com/u/lodi)\
**Post date:** [September 30, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/issue-with-jopenssl/176459/1 "2009-09-30T21:51:52Z")

</div>

Hi,

I am running jopenssl 0.5.2 and it errors out when encrypting data,  
but this works correctly with openssl. The cipher I used is DES-CBC  
with no padding. Test case along with results for both ruby and jruby  
are shown below.

Please kindly help as we have a very tight deadline to meet and this  
is a show-stopper for us.

# Test case for irb

irb  
require ‘openssl’  
key = “0599E113A7EE32A9”  
data =  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
c1 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
c1.padding = 0  
c1.encrypt  
c1.key = key  
e = c1.update data  
e \<\< c1.final

c2 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
c2.padding = 0  
c2.decrypt  
c2.key = key  
d = c2.update e  
d \<\< c2.final

# Test case for Jruby irb (same as above but using jruby/jopenssl)

jruby -S irb  
require ‘openssl’  
key = “0599E113A7EE32A9”  
data =  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
c1 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
c1.padding = 0  
c1.encrypt  
c1.key = key  
e = c1.update data  
e \<\< c1.final

c2 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
c2.padding = 0  
c2.decrypt  
c2.key = key  
d = c2.update e  
d \<\< c2.final

# Result from irb (Correct behavior, can encrypt and decrypt the data successfully using the same key)

irb  
irb(main):001:0\> require ‘openssl’  
=\> true  
irb(main):002:0\> key = “0599E113A7EE32A9”  
=\> “0599E113A7EE32A9”  
irb(main):003:0\> data =  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
=\>  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
irb(main):004:0\>  
irb(main):005:0\* c1 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
=\> #OpenSSL::Cipher::Cipher:0x101211f68  
irb(main):006:0\> c1.padding = 0  
=\> 0  
irb(main):007:0\> c1.encrypt  
=\> #OpenSSL::Cipher::Cipher:0x101211f68  
irb(main):008:0\> c1.key = key  
=\> “0599E113A7EE32A9”  
irb(main):009:0\> e = c1.update data  
=\>  
“Bh\267\365\303\203\212\317\255+(\332=1#x\366\252\336\331\213\031:\274\244\222\357n7\233\233\223]\342TN\202RC10\250\2458\204\347!\270l,\357\352\357\315\303\341L\001\373\244\023\304h03\272\246"\342\213\256\314\240\340\272YS\375\306\026\306\366\220k\t\346Z\0302\2442\263\336\315\277q\271\255\001:\017I\201\351\177\a\264\352\>\003\252k\330\245\362\332\205Si[P\206\323\256\322\034l\325”  
irb(main):010:0\> e \<\< c1.final  
=\>  
“Bh\267\365\303\203\212\317\255+(\332=1#x\366\252\336\331\213\031:\274\244\222\357n7\233\233\223]\342TN\202RC10\250\2458\204\347!\270l,\357\352\357\315\303\341L\001\373\244\023\304h03\272\246"\342\213\256\314\240\340\272YS\375\306\026\306\366\220k\t\346Z\0302\2442\263\336\315\277q\271\255\001:\017I\201\351\177\a\264\352\>\003\252k\330\245\362\332\205Si[P\206\323\256\322\034l\325”  
irb(main):011:0\>  
irb(main):012:0\* c2 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
=\> #OpenSSL::Cipher::Cipher:0x1011ddba0  
irb(main):013:0\> c2.padding = 0  
=\> 0  
irb(main):014:0\> c2.decrypt  
=\> #OpenSSL::Cipher::Cipher:0x1011ddba0  
irb(main):015:0\> c2.key = key  
=\> “0599E113A7EE32A9”  
irb(main):016:0\> d = c2.update e  
=\>  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
irb(main):017:0\> d \<\< c2.final  
=\>  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
irb(main):018:0\>

# Result from Jruby irb (incorrect behavior, errors out when trying to decrypt using the same key)

jruby -S irb  
irb(main):001:0\> require ‘openssl’  
=\> true  
irb(main):002:0\> key = “0599E113A7EE32A9”  
=\> “0599E113A7EE32A9”  
irb(main):003:0\> data =  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
=\>  
“1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
irb(main):004:0\>  
irb(main):005:0\* c1 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
=\> #OpenSSL::Cipher::Cipher:0x294ff81a  
irb(main):006:0\> c1.padding = 0  
=\> 0  
irb(main):007:0\> c1.encrypt  
=\> #OpenSSL::Cipher::Cipher:0x294ff81a  
irb(main):008:0\> c1.key = key  
=\> “0599E113A7EE32A9”  
irb(main):009:0\> e = c1.update data  
=\>  
“X\235\274\373\261M\273rP\e(\320\322e\371fJH1\213\350\234a\004\361\211\350\>2\345\000\354`\272\032!?\270W\275\221\025\241I\253Y\207\330\324c!\370\332\211\273*\275\323\227TB\217\376\324i\fv\357l}\305)\341\tT\330\230l\332\250\227h\202/!\366UZ\202 c\0358\362\03165\335\027\304\317\211\202\347\236\031\352\345\375\004o%\025w\350\375\265\e\005C\374\b9\325\334T\267\270" irb(main):010:0> e << c1.final => "X\235\274\373\261M\273rP\e(\320\322e\371fJH1\213\350\234a\004\361\211\350>2\345\000\354`\272\032!?\270W\275\221\025\241I\253Y\207\330\324c!\370\332\211\273\*\275\323\227TB\217\376\324i\fv\357l}\305)\341\tT\330\230l\332\250\227h\202/!\366UZ\202  
c\0358\362\03165\335\027\304\317\211\202\347\236\031\352\345\375\004o%\025w\350\375\265\e\005C\374\b9\325\334T\267\270”  
irb(main):011:0\>  
irb(main):012:0\* c2 = OpenSSL::Cipher::Cipher.new(“DES-CBC”)  
=\> #OpenSSL::Cipher::Cipher:0x62c639ce  
irb(main):013:0\> c2.padding = 0  
=\> 0  
irb(main):014:0\> c2.decrypt  
=\> #OpenSSL::Cipher::Cipher:0x62c639ce  
irb(main):015:0\> c2.key = key  
=\> “0599E113A7EE32A9”  
irb(main):016:0\> d = c2.update e  
OpenSSL::Cipher::CipherError: No message available  
from (irb):17  
irb(main):017:0\> d \<\< c2.final  
OpenSSL::Cipher::CipherError: Cipher not initialized  
from (irb):18  
irb(main):018:0\>

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![lodi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@lodi](https://www.ruby-forum.com/u/lodi)\
**Post date:** [October 1, 2009, 3:46am UTC](https://www.ruby-forum.com/t/issue-with-jopenssl/176459/2 "2009-10-01T03:46:02Z")

</div>

Hi, would you mind turning this into a test/unit-style test case and  
file it in a JIRA ([http://jira.codehaus.org/browse/JRUBY](http://jira.codehaus.org/browse/JRUBY))? That will  
help us track the problem. We can’t guarantee a quick turnaround for  
community requests, but if you think your team might be interested in  
support please send me a separate email at [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).

Thanks,  
/Nick

On Wed, Sep 30, 2009 at 12:44 PM, Anthony L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> # Test case for irb e = c1.update data
> 
> e \<\< c1.final  
> Result from irb (Correct behavior, can encrypt and decrypt the data  
> “1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
> =\>  
> =\> #OpenSSL::Cipher::Cipher:0x1011ddba0  
> Result from Jruby irb (incorrect behavior, errors out when trying to decrypt  
> “1234567890~5J96LC303C1D22DD~20090930005944~http%3A%2F%2Flocalhost%3A8080%2Flogin%3B0%3B1~http%3A%2F%[2Fmix-stage.oracle.com](http://2Fmix-stage.oracle.com)%2F~00”  
> =\>  
> =\> 0  
> irb(main):018:0\>
> 
> * * *
> 
> To unsubscribe from this list, please visit:
> 
> [http://xircles.codehaus.org/manage\_email](http://xircles.codehaus.org/manage_email)

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```
