Encrypting a string with Blowfish in ruby returns a shorter string than the same process in php -


This is confusing me

When I encrypt a string with bluffish to the following I try to use the input key = "some key" input = "input string"

I get the following results: < P> I am going to get the string from a PHP application, so I need to sync these two, but I do not understand That PHP string is now more reasons to remember me?

PHP Code:

  php> Need_once 'Crypt / Blowfish.php'; Php & gt; $ Input = "input string"; Php & gt; $ Key = "some key"; Php & gt; $ Crypt = new crypt_blowfish ($ key); Php & gt; Echo bin2hex ($ crypt-> encrypt ($ input)); 79af8c8ee9220bdec2d1c9cfca7b13c6   

Ruby code:

  irb (main): 001: 0 & gt; Requires 'rubygems' = & gt; True IRB (Main): 002: 0> 'Crypt / Bluefish' = & gt; True IRB (Main): 003: 0> Input = "input string" = & gt; "Input String" irb (main): 004: 0> Key = "some key" = & gt; "Some Keys" IRB (Main): 005: 0> Blowfish = crypt :: blowfish.new (key) = & gt; # & Lt; crypt :: blowfish: 0xb74b10c4 @sBoxes = [[3156471959, 1769696695, 1443271708, 181204541, ...... 18 94848609], @ key = "some key" & gt; IRB (Main): 006: 0> Blowfish.encrypt_block (input) = & gt; "Y \ 257 \ 214 \ 216 \ 351 \" \ v \ 336 "irb (main): 007: 0 & gt; Bfifis.ankrrip_blok (input) Kanpak (" H * ") = & gt; [" 79af8c8ee9220bde " ]    

assuming that Crypt_Blowfish is either used Or works, you are facing a padding problem. Specifically, the string is being pad right with empty bytes, unless the block size is greater than one. From the PHP interactive shell:

  php> $ Bf = mc rypt_module_open ( 'bluffish', '', 'ecb', ''); php & gt; $ iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ bf), mcrypT_dev_RANDOM); php & gt; $ key = 'a key'; php & Gt ; Mcrypt_generic_init ($ bf, $ key, $ iv); php> echo mcrypt_enc_get_block_size ($ td); 8 php> echo bin 2 hex (mcrypt_generic ($ bf, 'input string')); 79 flycoxy 9220bdec2d1c9cfca7b13c6 php & gt; echo bin2hex Mcrypt_generic ($ td, "input string \ 0 \ 0 \ 0 \ 0")); 79 F 8 C 8ee9220BCec2d1c9cfca7b13c6   

there is no obvious way to change < C Ode> mcrypt , and I do not know which library you have used to document the module Check the padding mode in Chhattisgarh.

With any luck, you can only set the padding mode of Ruby, or simply rub the blank on the string on the Ruby side.

Comments