MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / decrypt

Method decrypt

src/lib/pyelliptic/ecc.py:487–505  ·  view source on GitHub ↗

Decrypt data with ECIES method using the local private key

(self, data, ciphername='aes-256-cbc')

Source from the content-addressed store, hash-verified

485 return ciphertext + mac
486
487 def decrypt(self, data, ciphername='aes-256-cbc'):
488 """
489 Decrypt data with ECIES method using the local private key
490 """
491 # pylint: disable=too-many-locals
492 blocksize = OpenSSL.get_cipher(ciphername).get_blocksize()
493 iv = data[:blocksize]
494 i = blocksize
495 _, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:])
496 i += i2
497 ciphertext = data[i:len(data) - 32]
498 i += len(ciphertext)
499 mac = data[i:]
500 key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
501 key_e, key_m = key[:32], key[32:]
502 if not equals(hmac_sha256(key_m, data[:len(data) - 32]), mac):
503 raise RuntimeError("Fail to verify data")
504 ctx = Cipher(key_e, iv, 0, ciphername)
505 return ctx.ciphering(ciphertext)

Callers 4

eciesDecryptMethod · 0.80
eciesDecryptFunction · 0.80
testEncryptEciesMethod · 0.80
testDecryptEciesMethod · 0.80

Calls 9

raw_get_ecdh_keyMethod · 0.95
cipheringMethod · 0.95
equalsFunction · 0.85
hmac_sha256Function · 0.85
CipherClass · 0.85
get_cipherMethod · 0.80
_decode_pubkeyMethod · 0.80
get_blocksizeMethod · 0.45
digestMethod · 0.45

Tested by 2

testEncryptEciesMethod · 0.64
testDecryptEciesMethod · 0.64