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

Function eciesEncrypt

plugins/CryptMessage/CryptMessage.py:9–23  ·  view source on GitHub ↗
(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc')

Source from the content-addressed store, hash-verified

7
8
9def eciesEncrypt(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc'):
10 from lib import pyelliptic
11 pubkey_openssl = toOpensslPublickey(base64.b64decode(pubkey))
12 curve, pubkey_x, pubkey_y, i = pyelliptic.ECC._decode_pubkey(pubkey_openssl)
13 if ephemcurve is None:
14 ephemcurve = curve
15 ephem = pyelliptic.ECC(curve=ephemcurve)
16 key = hashlib.sha512(ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
17 key_e, key_m = key[:32], key[32:]
18 pubkey = ephem.get_pubkey()
19 iv = pyelliptic.OpenSSL.rand(pyelliptic.OpenSSL.get_cipher(ciphername).get_blocksize())
20 ctx = pyelliptic.Cipher(key_e, iv, 1, ciphername)
21 ciphertext = iv + pubkey + ctx.ciphering(data)
22 mac = pyelliptic.hmac_sha256(key_m, ciphertext)
23 return key_e, ciphertext + mac
24
25def eciesDecrypt(encrypted_data, privatekey):
26 ecc_key = getEcc(privatekey)

Callers

nothing calls this directly

Calls 9

raw_get_ecdh_keyMethod · 0.95
get_pubkeyMethod · 0.95
cipheringMethod · 0.95
toOpensslPublickeyFunction · 0.85
_decode_pubkeyMethod · 0.80
randMethod · 0.80
get_cipherMethod · 0.80
digestMethod · 0.45
get_blocksizeMethod · 0.45

Tested by

no test coverage detected