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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:40:51+00:00 2026-05-28T03:40:51+00:00

I have several strings that were encrypted using OpenSSL. For instance: $ echo original

  • 0

I have several strings that were encrypted using OpenSSL. For instance:

$ echo "original string" | openssl aes-256-cbc -p -a -pass pass:secret
salt=B898FE40EC8155FD
key=4899E518743EB0584B0811AE559ED8AD9F0B5FA31B0B998FEB8453B8E3A7B36C
iv =EFA6105F30F6C462B3D135725A6E1618
U2FsdGVkX1+4mP5A7IFV/VcgRs4ci/yupMErHjf5bkT5XrcowXK7z3VyyV1l2jvy

I would like to decrypt these things using Python. I’m attempting to use PyCrypto. Here’s an exmaple script using the above data:

from base64 import b64decode, b64encode
from hashlib import md5
from Crypto.Cipher import AES

secret = 'secret'
encoded = 'U2FsdGVkX1+4mP5A7IFV/VcgRs4ci/yupMErHjf5bkT5XrcowXK7z3VyyV1l2jvy'
encrypted = b64decode(encoded)
salt = encrypted[8:16]
data = encrypted[16:]
key = md5(secret + salt).hexdigest()
iv = md5(key + secret + salt).hexdigest()[0:16] # which 16 bytes?
dec = AES.new(key, AES.MODE_CBC, iv)
clear = dec.decrypt(data)

try:
    salt_hex = ''.join(["%X" % ord(c) for c in salt])
    print 'salt:     %s' % salt_hex
    print 'expected: %s' % 'B898FE40EC8155FD'
    print 'key:      %s' % key.upper()
    print 'expected: %s' % '4899E518743EB0584B0811AE559ED8AD9F0B5FA31B0B998FEB8453B8E3A7B36C'
    print 'iv:       %s' % iv
    print 'expected: %s' % 'EFA6105F30F6C462B3D135725A6E1618'
    print 'result: %s' % clear
except UnicodeDecodeError:
    print 'decryption failed'

Here’s the output:

salt:     B898FE40EC8155FD
expected: B898FE40EC8155FD
key:      4899E518743EB0584B0811AE559ED8AD
expected: 4899E518743EB0584B0811AE559ED8AD9F0B5FA31B0B998FEB8453B8E3A7B36C
iv:       17988376b72f4a81
expected: EFA6105F30F6C462B3D135725A6E1618
decryption failed

You can see that the salt matches, and the key matches the first half of what OpenSSL shows, so I seem to be on the right track, but there are two main questions:

  1. Why are the values for key and iv from OpenSSL twice as long as PyCrypto (and presumably AES256) allows?
  2. How do I generate the correct values? The technique I’m using was taken from a blog, but if the IV is always supposed to match the block size (16 bytes), MD5 will never work. And even if I could figure out where the other half of the key comes from, PyCrypto would refuse it for being too long.

I realize I’ll need to remove the padding as well, but I left that out for brevity.

  • 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-28T03:40:52+00:00Added an answer on May 28, 2026 at 3:40 am

    You have three problems:

    1. You use AES256 (32 byte key) in OpenSSL and AES128 (16 byte key) in your python code.
    2. The IV computation is wrong. Each step in the OpenSSL’s key derivation function uses the the MD5 digest computed last.
    3. You mix up binary and hexadecimal representation. Keep any conversion to hexadecimal as the last step, before visualization.

    The following code should be correct:

    from base64 import b64decode, b64encode
    from binascii import hexlify
    from Crypto.Cipher import AES
    from Crypto.Hash import MD5
    
    secret = 'secret'
    encoded = 'U2FsdGVkX1+4mP5A7IFV/VcgRs4ci/yupMErHjf5bkT5XrcowXK7z3VyyV1l2jvy'
    encrypted = b64decode(encoded)
    salt = encrypted[8:16]
    data = encrypted[16:]
    
    # We need 32 bytes for the AES key, and 16 bytes for the IV
    def openssl_kdf(req):
        prev = ''
        while req>0:
            prev = MD5.new(prev+secret+salt).digest()
            req -= 16
            yield prev
    mat = ''.join([ x for x in openssl_kdf(32+16) ])
    key = mat[0:32]
    iv  = mat[32:48]
    
    dec = AES.new(key, AES.MODE_CBC, iv)
    clear = dec.decrypt(data)
    
    try:
        salt_hex = ''.join(["%X" % ord(c) for c in salt])
        print 'salt:     %s' % salt_hex
        print 'expected: %s' % 'B898FE40EC8155FD'
        print 'key:      %s' % hexlify(key).upper()
        print 'expected: %s' % '4899E518743EB0584B0811AE559ED8AD9F0B5FA31B0B998FEB8453B8E3A7B36C'
        print 'iv:       %s' % hexlify(iv).upper()
        print 'expected: %s' % 'EFA6105F30F6C462B3D135725A6E1618'
        print 'result:   %s' % clear
    except UnicodeDecodeError:
        print 'decryption failed'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several strings that have been pulled using cURL from another website. The
I have several strings that will be replaced with the same string... ie $text=str_ireplace('[/VIDEO]','</div>',$text);
I have several strings that I need to parse. The string is supposed to
I have a Struts (1.3x) ActionForm that has several String and boolean properties/fields, but
So I have an iPhone application that needs to: Post several strings and up
I have several tables that contain several strings for fields. Some of these fields
I have an array of several news headlines ( just strings ) that I
i have several strings that look like this: contactBtn, programBtn, cartBtn. How can i
I have several strings in my site that don't belong to any app, for
I have several Java files that have Japanese strings in them, and are encoded

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.