Decrypt data with ECIES method using the local private key
(self, data, ciphername='aes-256-cbc')
| 461 | return ciphertext + mac |
| 462 | |
| 463 | def decrypt(self, data, ciphername='aes-256-cbc'): |
| 464 | """ |
| 465 | Decrypt data with ECIES method using the local private key |
| 466 | """ |
| 467 | blocksize = OpenSSL.get_cipher(ciphername).get_blocksize() |
| 468 | iv = data[:blocksize] |
| 469 | i = blocksize |
| 470 | curve, pubkey_x, pubkey_y, i2 = ECC._decode_pubkey(data[i:]) |
| 471 | i += i2 |
| 472 | ciphertext = data[i:len(data)-32] |
| 473 | i += len(ciphertext) |
| 474 | mac = data[i:] |
| 475 | key = sha512(self.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest() |
| 476 | key_e, key_m = key[:32], key[32:] |
| 477 | if not equals(hmac_sha256(key_m, data[:len(data) - 32]), mac): |
| 478 | raise RuntimeError("Fail to verify data") |
| 479 | ctx = Cipher(key_e, iv, 0, ciphername) |
| 480 | return ctx.ciphering(ciphertext) |
no test coverage detected