1

Digital Cinema Packages contain checksums in the following format as described here:

$ openssl sha1  -binary 'dcpfile.xml' |openssl base64
IxcfhXNHlw+1bbDFu0kp8KRylpU=

How can I take a value such as IxcfhXNHlw+1bbDFu0kp8KRylpU= and derive the original sha1 hash, which would look something like

$ openssl sha1 'dcpfile.xml' 
SHA1(dcpfile.xml)= 23171f857347970fb56db0c5bb4929f0a4729695

My use case is that there are not many checksum validation tools that exist that easily allow you to validate an md5sum type checksum manifest that use these binary/base64 values, but there are many tools that validate sha1, so it would be great if I knew how to reverse these values so I could write a script that would generate a more interoperable list of hashes.

0

1 Answer 1

1

Both values are the same hash – the same "binary" bytes shown in two different encodings (representations), and neither is more "original" than the other.

(Base64 has 6 bits per character; hexadecimal aka base-16 has 4 bits per digit. Three raw bytes, four Base64 digits, six hex digits are directly convertible.)

Just about every programming language will have functions to encode/decode these formats. For example, in shell tools:

  • To decode Base64 into raw binary data, use base64 -d or openssl base64 -d.

  • To encode raw binary data into hexadecimal, use xxd -p or hexdump.

$ echo 23171f857347970fb56db0c5bb4929f0a4729695 | xxd -r -p | base64
IxcfhXNHlw+1bbDFu0kp8KRylpU=

$ echo IxcfhXNHlw+1bbDFu0kp8KRylpU= | base64 -d | hd
00000000  23 17 1f 85 73 47 97 0f  b5 6d b0 c5 bb 49 29 f0  |#...sG...m...I).|
00000010  a4 72 96 95                                       |.r..|
4
  • Perfect, so this openssl sha1 -binary 'dcp_file.xml' |openssl base64 | base64 -d | xxd -p will produce 23171f857347970fb56db0c5bb4929f0a4729695 - now I just need to do it all in python which I think you have told me how to figure out. Thank you!
    – kieran
    Commented Apr 4, 2018 at 17:45
  • 1
    Import base64 and binascii. Commented Apr 4, 2018 at 17:48
  • Thank you!! This will make my life so much easier.
    – kieran
    Commented Apr 4, 2018 at 17:52
  • import binascii import base64 a = 'IxcfhXNHlw+1bbDFu0kp8KRylpU=' b = base64.b64decode(a) binascii.hexlify(b).decode() u'23171f857347970fb56db0c5bb4929f0a4729695'
    – kieran
    Commented Apr 4, 2018 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .