pybitmessage.pyelliptic.ecc module¶
Asymmetric cryptography using elliptic curves
-
class
ECC
(pubkey=None, privkey=None, pubkey_x=None, pubkey_y=None, raw_privkey=None, curve='sect283r1')[source]¶ Bases:
object
Asymmetric encryption with Elliptic Curve Cryptography (ECC) ECDH, ECDSA and ECIES
>>> from binascii import hexlify >>> import pyelliptic
>>> alice = pyelliptic.ECC() # default curve: sect283r1 >>> bob = pyelliptic.ECC(curve='sect571r1')
>>> ciphertext = alice.encrypt("Hello Bob", bob.get_pubkey()) >>> print(bob.decrypt(ciphertext))
>>> signature = bob.sign("Hello Alice") >>> # alice's job : >>> print(pyelliptic.ECC( >>> pubkey=bob.get_pubkey()).verify(signature, "Hello Alice"))
>>> # ERROR !!! >>> try: >>> key = alice.get_ecdh_key(bob.get_pubkey()) >>> except: >>> print( "For ECDH key agreement, the keys must be defined" " on the same curve!")
>>> alice = pyelliptic.ECC(curve='sect571r1') >>> print(hexlify(alice.get_ecdh_key(bob.get_pubkey()))) >>> print(hexlify(bob.get_ecdh_key(alice.get_pubkey())))
-
static
get_curves
()¶ Static method, returns the list of all the curves available
-
get_curve
()¶ The name of currently used curve
-
get_curve_id
()¶ Currently used curve
-
get_pubkey
()¶ High level function which returns : curve(2) + len_of_pubkeyX(2) + pubkeyX + len_of_pubkeyY + pubkeyY
-
get_privkey
()¶ High level function which returns curve(2) + len_of_privkey(2) + privkey
-
get_ecdh_key
(pubkey)¶ High level function. Compute public key with the local private key and returns a 512bits shared key.
-
raw_get_ecdh_key
(pubkey_x, pubkey_y)¶ ECDH key as binary data
-
check_key
(privkey, pubkey)¶ Check the public key and the private key. The private key is optional (replace by None).
-
raw_check_key
(privkey, pubkey_x, pubkey_y, curve=None)¶ Check key validity, key is supplied as binary data
-
sign
(inputb, digest_alg=<_FuncPtr object>)¶ Sign the input with ECDSA method and returns the signature
-
verify
(sig, inputb, digest_alg=<_FuncPtr object>)¶ Verify the signature with the input and the local public key. Returns a boolean.
-
static
encrypt
(data, pubkey, ephemcurve=None, ciphername='aes-256-cbc')¶ Encrypt data with ECIES method using the public key of the recipient.
-
static
raw_encrypt
(data, pubkey_x, pubkey_y, curve='sect283r1', ephemcurve=None, ciphername='aes-256-cbc')¶ ECDH encryption, keys supplied in binary data format
-
decrypt
(data, ciphername='aes-256-cbc')¶ Decrypt data with ECIES method using the local private key
-
static