Exemplo n.º 1
0
 def raw_encrypt(data, pubkey_x, pubkey_y, curve='sect283r1', ephemcurve=None, ciphername='aes-256-cbc'):
     if ephemcurve == None: ephemcurve = curve
     ephem = ecc(curve=ephemcurve)
     key = ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)
     pubkey = ephem.get_pubkey()
     iv = openssl.rand(openssl.get_cipher(ciphername).get_blocksize())
     ctx = cipher(key, iv, 1, ciphername)
     return iv + pubkey + ctx.ciphering(data)
Exemplo n.º 2
0
 def decrypt(self, data, ciphername='aes-256-cbc'):
     """
     Decrypt data with ECIES method using the local private key
     """
     blocksize = openssl.get_cipher(ciphername).get_blocksize()
     iv = data[:blocksize]
     i = blocksize
     curve, pubkey_x, pubkey_y, i2 = ecc._decode_pubkey(data[i:])
     i += i2
     data = data[i:]
     key = self.raw_get_ecdh_key(pubkey_x, pubkey_y)
     ctx = cipher(key, iv, 0, ciphername)
     return ctx.ciphering(data)