Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:48:34+00:00 2026-06-14T07:48:34+00:00

Why is there a difference in blowfish encryption between Crypt::CBC (perl) and OpenSSL (ruby)?

  • 0

Why is there a difference in blowfish encryption between Crypt::CBC (perl) and OpenSSL (ruby)?

Perl

use Crypt::CBC;

my $cipher = Crypt::CBC->new( -key => 'length32length32length32length32', -cipher => 'Blowfish' );
my $ciphertext = $cipher->encrypt_hex('test');

# ciphertext is 53616c7465645f5f409c8b8eb353823c06d9b50537c92e19

Ruby

require "rubygems"
require "openssl"

cipher = OpenSSL::Cipher::Cipher.new("bf-cbc")
cipher.encrypt
cipher.key = "length32length32length32length32"

result = cipher.update("test") << cipher.final
ciphertext = result.unpack("H*").first

# ciphertext is 16f99115a09e0464

Crypt::CBC seems to be prepending Salted__ to the output by default. Can you explain what is going on that is so different between these? Is there a way to make OpenSSL behave in a similar way to Crypt::CBC?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:48:35+00:00Added an answer on June 14, 2026 at 7:48 am

    Crypt::CBC (perl) uses its own method to randomize the salt and initialization vector. Plus in the case of Blowfish it uses a key length of 56 as mentioned above.

    Using the perl code from your example:

    Perl

    use Crypt::CBC;
    
    my $cipher = Crypt::CBC->new( -key => 'length32length32length32length32', -cipher =>  'Blowfish' );
    my $ciphertext = $cipher->encrypt_hex('test');
    # 53616c7465645f5f409c8b8eb353823c06d9b50537c92e19
    

    To decode this using ruby (OpenSSL) requires a little tweaking to extract the key and initialization vector:

    Ruby

    require 'openssl'
    
    # Hex string to decode(from above)
    string = '53616c7465645f5f409c8b8eb353823c06d9b50537c92e19'
    
    # Pack Hex
    string = [string].pack('H*')
    
    # Some Config
    pass = 'length32length32length32length32'
    key_len = 56;
    iv_len  = 8;
    desired_len = key_len + iv_len;
    salt_re = /^Salted__(.{8})/
    
    #Extract salt
    salt = salt_re.match(string)
    salt = salt.captures[0]
    data  = '';
    d = '';
    while (data.length < desired_len)
      d = Digest::MD5::digest("#{d}#{pass}#{salt}");
      data << d;
    end
    
    #Now you have extracted your key and initialization vector
    key = data.slice(0..key_len-1)
    iv = data.slice(key_len .. -1)
    
    # Trim string of salt
    string = string[16..-1]
    
    cipher = OpenSSL::Cipher::Cipher.new "bf-cbc"
    cipher.decrypt
    cipher.key_len = key_len
    cipher.key = key
    cipher.iv = iv
    
    puts cipher.update(string) << cipher.final
    # test   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a difference between using PHPs time() and using new MongoDate() ? I
Is there a difference between the two examples below for beginning a Perl script?
Is there any difference between var obj1 = new Constructor; and var obj2 =
Is there difference in behavior between a constructor call and a procedure call in
Is there any difference (compiler/interpreter/juju wise, etc) between the two versions of checking the
Is there any difference between ReferencePath with condition '%(CopyLocal)'=='true' and ReferenceCopyLocalPaths ? The question
Is there a difference between this.form and document.forms (document[forms]) or, are they similar? Here
Is there any difference between: public ActionResult logOff() { FormsAuth.SignOut(); return RedirectToAction(index, Home); }
Is there any difference between '{' and '[' when formatting a JSON object?
is there a difference between: mvt_act_idx = openCloseList.size()-1; openCloseList[mvt_act_idx].A += a; and openCloseList.back().A +=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.