Skip to content

Instantly share code, notes, and snippets.

@zgrge
Created November 18, 2020 11:11
Show Gist options
  • Save zgrge/4badc8bf542ac94a9039d79beb33f57e to your computer and use it in GitHub Desktop.
Save zgrge/4badc8bf542ac94a9039d79beb33f57e to your computer and use it in GitHub Desktop.
Generate the hash for an EMV CA public key
from hashlib import sha1
'''
example of how to calculate SHA-1 hash from EMV CA Public Key in python using VISA 0x09 CA PK
'''
rid = 'A000000003'
index = '09'
modulus = '9D912248DE0A4E39C1A7DDE3F6D2588992C1A4095AFBD1824D1BA74847F2BC4926D2EFD904B4B54954CD189A54C5D1179654F8F9B0D2AB5F0357EB642FEDA95D3912C6576945FAB897E7062CAA44A4AA06B8FE6E3DBA18AF6AE3738E30429EE9BE03427C9D64F695FA8CAB4BFE376853EA34AD1D76BFCAD15908C077FFE6DC5521ECEF5D278A96E26F57359FFAEDA19434B937F1AD999DC5C41EB11935B44C18100E857F431A4A5A6BB65114F174C2D7B59FDF237D6BB1DD0916E644D709DED56481477C75D95CDD68254615F7740EC07F330AC5D67BCD75BF23D28A140826C026DBDE971A37CD3EF9B8DF644AC385010501EFC6509D7A41'
exponent = '03'
def emvhash(rid, index, modulus, exponent):
h = bytes()
for i in (rid, index, modulus, exponent):
h = h + bytes.fromhex(i)
return sha1(h).hexdigest().upper()
print(emvhash(rid, index, modulus, exponent))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment