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 6476139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:47:19+00:00 2026-05-25T06:47:19+00:00

I have some testdata key/text/encrypted from an API provider and am now trying to

  • 0

I have some testdata key/text/encrypted from an API provider and am now trying to yield the same encrypted result with the function below, but my result diverts from the provided one in the last 16 of 241 digits. Do you have an idea, what the reason may be?
I ensured, that ‘bf-ecb’ is the right mode, and experimented with url-encoding, but so far without success.

require 'openssl'

def encrypt(key, data)
    cipher = OpenSSL::Cipher::Cipher.new('bf-ecb').send(:encrypt)
    cipher.key = key
    result = cipher.update(data) << cipher.final

    hexed = ''
    result.each_byte { |c| hexed << '%02x' % c }
    hexed.upcase
end

UPDATE

Also trying to decrypt the example result results in an OpenSSL::Cipher::CipherError “bad decrypt”

  • 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-05-25T06:47:20+00:00Added an answer on May 25, 2026 at 6:47 am

    It was indeed a problem with the padding. I worked around it with deactivating it and implementing it by myself.
    So far it works.

    This is how it looks like:

    require 'openssl'
    
    def encrypt(key,data)
      cipher = OpenSSL::Cipher::Cipher.new "bf-ecb"
      cipher.padding = 0
      cipher.key = key
      cipher.encrypt
      enhex(cipher.update padd data)
    end
    def decrypt(key,data,len)
      cipher = OpenSSL::Cipher::Cipher.new "bf-ecb"
      cipher.padding = 0
      cipher.key = key
      cipher.decrypt
      (cipher.update dehex(data)).slice(0,len)
    end
    def enhex(data)
      hexed = ''
      data.each_byte { |c| hexed << '%02x' % c }
      hexed.upcase
    end
    def dehex(data)
      data.scan(/../).map{ |b| b.to_i(16) }.pack('C*')
    end 
    def padd(data)
      data + " "*(8 - (data.length % 8))
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SqlServer database that I've manually filled with some test data. Now
I have some code where I am trying to use variables in a tabpage.
I have a list of words that I want to exclude from some query
I have text file(test.data), which include some values and class name, for example 4.5,3.5,U1
I have a table with some persistent data in it. Now when I query
I have made an SQLite database file with some testdata in it. When I
I have a JTable with some fields with long text and some with little
I have a command Get-Testdata that retrieves test data from different sources and stores
I have a pre-constructed array created from some test data as I have not
Currently I am trying to load some Xaml files to create testdata. I used

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.