How do I print a fingerprint (sha256 bytes) using colon notation?

Alphadelta14

I have an x509 certificate fingerprint which is basically just a SHA 256 byte string.

These are usually notated in the form 43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8.

Is there a more appropriate way to generate these from a byte string like b'CQC\xa1\xb5\xfc\x8b\xb7\n:\xa9\xb1\x0ffs\xa8'?

binascii.hexlify(b'CQC\xa1\xb5\xfc\x8b\xb7\n:\xa9\xb1\x0ffs\xa8') gets me halfway there (b'435143a1b5fc8bb70a3aa9b10f6673a8'), but I don't have any of the colons.

fuzzy drawings
hashbytes = b'CQC\xa1\xb5\xfc\x8b\xb7\n:\xa9\xb1\x0ffs\xa8'
print(":".join([format(i,'02x') for i in hashbytes]))

43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8

There's probably a shorter way, perhaps with the format() method on the hexdigest() string output.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I create SHA256 HMAC using Ironclad in Common Lisp?

How do I specify the key for computing a SHA256 hash?

How Do I Convert a Picture into a Sha256 Hash Python

How do I sha256 raw bits in python?

How to verify the signing certificate on an APK matches the SHA256 fingerprint?

How to extract Sha256 Cert Fingerprint for Branch.io

using this code how do you know if sha256 or sha512 would be used?

How do I make the same SHA256 encoded string in Javascript that I do in Python 3?

How do I print a double value without scientific notation using Java?

how do I print the contents of an array of bytes as bytes?

How do I properly convert this SHA256 encryption function in PHP based off this Swift code?

how to generate SHA256 with 32 bytes for a given string?

How can I hash a string with SHA256 in JS?

How can I check a sha256 hash?

HMAC and SHA256 - how to validate using nonce

How to Decrypt RSA OAEP with SHA256 using openssl on PHP

How do i convert multi-byte integer values to 4bytes array using the two's compliment notation in the big-endian order

How do I get values from an object using dot notation

How do I return JSON such that it can be accessed using dot notation?

How to convert md5 32 bytes hash to corresponding sha256 in python

How do I remove the colon from DriveLetter

How do I match a colon with no values after it?

Calculating sha256 gives different results after appending slices depending on if I print out the slice before or not

How do I decode bytes using pyserial in serial communication

How do I reformat .JSON key value pairs to comma-separated values using equals instead of colon?

How do i delete all the lines in a file ending with colon using awk or sed?

Python: How can I print bytes?

How can I print 4 bytes as an integer

How to hash output of sha256 with sha256 in rust