(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc')
| 7 | |
| 8 | |
| 9 | def 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 | |
| 25 | def eciesDecrypt(encrypted_data, privatekey): |
| 26 | ecc_key = getEcc(privatekey) |
nothing calls this directly
no test coverage detected