MCPcopy Create free account
hub / github.com/ActiveState/code / decrypt

Method decrypt

recipes/Python/576980_Authenticated/recipe-576980.py:47–58  ·  view source on GitHub ↗

verify HMAC-SHA256 signature and decrypt data with AES-CBC

(self, data)

Source from the content-addressed store, hash-verified

45 return data + sig
46
47 def decrypt(self, data):
48 """verify HMAC-SHA256 signature and decrypt data with AES-CBC"""
49 aes_key, hmac_key = self.keys
50 sig = data[-self.SIG_SIZE:]
51 data = data[:-self.SIG_SIZE]
52 if hmac.new(hmac_key, data, hashlib.sha256).digest() != sig:
53 raise AuthenticationError("message authentication failed")
54 iv_bytes = data[:self.AES_BLOCK_SIZE]
55 data = data[self.AES_BLOCK_SIZE:]
56 cypher = AES.new(aes_key, AES.MODE_CBC, iv_bytes)
57 data = cypher.decrypt(data)
58 return data[:-ord(data[-1])]
59
60 def dumps(self, obj, pickler=pickle):
61 """pickle and encrypt a python object"""

Callers 1

loadsMethod · 0.95

Calls 3

AuthenticationErrorClass · 0.85
digestMethod · 0.80
newMethod · 0.45

Tested by

no test coverage detected