This repository has been archived on 2024-12-19. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-19/src/pyelliptic
2019-10-22 20:09:42 +05:30
..
__init__.py __init__ pylint fixes 2019-09-27 13:10:24 +05:30
arithmetic.py Solved encode-decode, pack-unpack, new address creation issues 2019-10-22 20:09:42 +05:30
cipher.py initial commit for python forward porting 2019-10-09 17:57:13 +05:30
ecc.py Solved encode-decode, pack-unpack, new address creation issues 2019-10-22 13:07:54 +05:30
eccblind.py Minor refactoring to separate objects 2019-08-27 23:13:58 +02:00
hash.py initial commit for python forward porting 2019-10-09 17:57:13 +05:30
LICENSE Debian packaging 2013-04-01 20:23:32 +01:00
openssl.py Solved encode-decode, pack-unpack, new address creation issues 2019-10-22 20:09:42 +05:30
README.md Debian packaging 2013-04-01 20:23:32 +01:00

PyElliptic

PyElliptic is a high level wrapper for the cryptographic library : OpenSSL. Under the GNU General Public License

Python3 compatible. For GNU/Linux and Windows. Require OpenSSL

Features

Asymmetric cryptography using Elliptic Curve Cryptography (ECC)

  • Key agreement : ECDH
  • Digital signatures : ECDSA
  • Hybrid encryption : ECIES (like RSA)

Symmetric cryptography

  • AES-128 (CBC, OFB, CFB)
  • AES-256 (CBC, OFB, CFB)
  • Blowfish (CFB and CBC)
  • RC4

Other

  • CSPRNG
  • HMAC (using SHA512)
  • PBKDF2 (SHA256 and SHA512)

Example

#!/usr/bin/python

import pyelliptic

# Symmetric encryption
iv = pyelliptic.Cipher.gen_IV('aes-256-cfb')
ctx = pyelliptic.Cipher("secretkey", iv, 1, ciphername='aes-256-cfb')

ciphertext = ctx.update('test1')
ciphertext += ctx.update('test2')
ciphertext += ctx.final()

ctx2 = pyelliptic.Cipher("secretkey", iv, 0, ciphername='aes-256-cfb')
print ctx2.ciphering(ciphertext)

# Asymmetric encryption
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 alice.get_ecdh_key(bob.get_pubkey()).encode('hex')
print bob.get_ecdh_key(alice.get_pubkey()).encode('hex')