Last active
September 8, 2021 18:27
-
-
Save rrudolph/1e1842e244aeb184b6e0ff8ce19fc171 to your computer and use it in GitHub Desktop.
For decoding the base64-encoded smart health card string from the COVID vaccine digital record qr code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Want to know exactly what is in your covid vaccine QR code issued to you? | |
| Decode it with a QR code reader and paste it into the qr_data variable and run. | |
| Credit to this post for the detailed explaination. | |
| source: https://marcan2020.medium.com/reversing-smart-health-cards-e765157fae9 | |
| ''' | |
| import re | |
| import base64 | |
| import zlib | |
| import json | |
| # Test data | |
| qr_data = "shc:/5676290952432060346029243740446031222959532654603460292540772804336028702864716745222809286133314564376531415906402203064504590856435503414245413640370636654171372412363803043756220467374075323239254334433260573601064137333912707426350769625364643945753638652852454535422237213876065244343160343853740855723835636810685712126967072534581208054242090543775073110024063411383336384168693404326438364025053330552640380527553266755975446326292974413411056375657045663941260836750066626744127412650663127253774252117654553004036442077072245263447552396237296363611221586172000544735026415257102476406874090854520923402064454566057720605333353934523368773871546530776725763450342565270512452950667144696836651240677707414450263141560604352333532003736845240800330361202740101109546920397733456645083937637609203027360726634458682836233328113628267258713820556229113823256320740622123930215842537423572004420710042656314532122903217620424036426535537233424468614545526029333777375400597640290855673469692837506528526454704235317710211074046236075568056803204261355358593854710965683963206060613074620371206276526908647361650966596729532435110866774371422326305965330806350309262568296071073576416838572162753826256111390939696044072526303708654339526630082969367063352624652758581035115720282541316556345038742028531057577664595060035950356103263224575274772852380524117676306959213045542735064574412725452105296452767569230552230407054459645772060333605629433612433458266759650955363961412506222210365642303659005505652370403040685523625756656041735607587042293709424506646233590554552026245328442240411032560021087508543027736505634128076253450922743327033912616606455705636141737439260957730567605771732564092369322610685243405706235524716655736168555859204110096054703057296325743307050338065932636944093409395007271232395239572967555621340812393377387667724370357625555064570306410670504157731153010937290945257435376870415523437024405223596237660372066530220454382258331044763532047171566835776037335324623255734037696245065352242275686423765336736726304164246669393374" | |
| parts = re.findall('..', qr_data[5:]) | |
| # print(parts) | |
| jws = "" | |
| for p in parts: | |
| jws += chr(int(p)+ 45) | |
| # print("jws:", jws) | |
| def decode(data): | |
| missing_padding = len(data) % 4 | |
| if missing_padding: | |
| data += '='* (4 - missing_padding) | |
| return base64.urlsafe_b64decode(data) | |
| jws_parts = list(map(decode, jws.split("."))) | |
| # print("jws parts:", jws_parts) | |
| print("header:", jws_parts[0]) | |
| # https://bugs.python.org/issue5784 | |
| shc_data = zlib.decompress(jws_parts[1], wbits=-15) | |
| json_object = json.loads(shc_data) | |
| print("SHC Data:", json.dumps(json_object, indent=2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment