{"id":27283861,"url":"https://github.com/purplesyringa/sslcrypto","last_synced_at":"2025-04-11T18:46:21.593Z","repository":{"id":56204377,"uuid":"219830310","full_name":"purplesyringa/sslcrypto","owner":"purplesyringa","description":"Simple ECIES, ECDSA and AES library for Python, supporting OpenSSL and pure-Python environments","archived":false,"fork":false,"pushed_at":"2020-11-21T04:41:47.000Z","size":298,"stargazers_count":27,"open_issues_count":8,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T13:48:49.360Z","etag":null,"topics":["aes","ciphers","ecdsa","ecies","elliptic-curves","library","openssl","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purplesyringa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-05T19:08:57.000Z","updated_at":"2024-08-24T10:00:34.000Z","dependencies_parsed_at":"2022-08-15T14:40:23.964Z","dependency_job_id":null,"html_url":"https://github.com/purplesyringa/sslcrypto","commit_stats":null,"previous_names":["purplesyringa/sslcrypto","imachug/sslcrypto"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purplesyringa%2Fsslcrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purplesyringa%2Fsslcrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purplesyringa%2Fsslcrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purplesyringa%2Fsslcrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purplesyringa","download_url":"https://codeload.github.com/purplesyringa/sslcrypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248462002,"owners_count":21107775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","ciphers","ecdsa","ecies","elliptic-curves","library","openssl","python"],"created_at":"2025-04-11T18:46:21.105Z","updated_at":"2025-04-11T18:46:21.581Z","avatar_url":"https://github.com/purplesyringa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sslcrypto\n\n[![Actions Status](https://github.com/imachug/sslcrypto/workflows/tests/badge.svg)](https://github.com/imachug/sslcrypto/actions)\n![Code Quality](https://raw.githubusercontent.com/imachug/sslcrypto/gh-action/quality.svg?sanitize=true)\n![Code Coverage](https://raw.githubusercontent.com/imachug/sslcrypto/gh-action/coverage.svg?sanitize=true)\n[![PyPI](https://img.shields.io/pypi/v/sslcrypto)](https://pypi.org/project/sslcrypto/)\n\n**sslcrypto** is a fast and simple library for AES, ECIES and ECDSA for Python.\n\nLicense: MIT + BSD-2 for ripemd implementation (see `_ripemd.py`).\n\n\n## Why?\n\n**sslcrypto** can use OpenSSL in case it's available in your system for speedup,\nbut pure-Python code is also available and is heavily optimized.\n\n**N.B.** There are alternatives like coincurve which are faster in some cases\n(e.g. when using secp256k1). They don't include ECIES implementation and some\nuseful ECDSA features and are specialized on a single curve. If that's enough\nfor you and libsecp256k1 bindings are available for all OSes you need to\nsupport, use those libraries. [Coincurve](https://github.com/ofek/coincurve),\nin particular, ships pre-compiled packages for all major OSes and building from\nsource does not require an existing libsecp256k1 installation.\n\n**N.B.** While there are other mature cryptography libraries, they are too heavy\nfor simple stuff and require OpenSSL that is not available by default on Windows\n(most likely many other OSes as well). That said, in case you're processing\n*big* data, not *much* data, the speed advantage you get from libraries is too\nsmall to use heavy alternatives.\n\n\n## Installation\n\n```\npip install sslcrypto\n```\n\nAdditionally, you can download this repository and run\n`python setup.py install`.\n\n\n## Usage\n\n### AES\n\n```python\nimport sslcrypto\n\n# Generate random key\nkey = sslcrypto.aes.new_key()\n\n# Encrypt something\ndata = b\"Hello, world!\"\nciphertext, iv = sslcrypto.aes.encrypt(data, key)\n\n# Decrypt\nassert sslcrypto.aes.decrypt(ciphertext, iv, key) == data\n```\n\nBy default, aes-256-cbc cipher is used. You can specify another one if you want.\nThe following ciphers are supported:\n\n- aes-128-cbc, aes-192-cbc, aes-256-cbc\n- aes-128-ctr, aes-192-ctr, aes-256-ctr\n- aes-128-cfb, aes-192-cfb, aes-256-cfb\n- aes-128-ofb, aes-192-ofb, aes-256-ofb\n\n```python\nimport sslcrypto\n\n# Generate random key\nkey = sslcrypto.aes.new_key(algo=\"aes-192-cfb\")\n\n# Encrypt something\ndata = b\"Hello, world!\"\nciphertext, iv = sslcrypto.aes.encrypt(data, key, algo=\"aes-192-cfb\")\n\n# Decrypt\nassert sslcrypto.aes.decrypt(ciphertext, iv, key, algo=\"aes-192-cfb\") == data\n```\n\n\n### ECIES\n\nThe following curves are supported:\n\n- secp112r1, secp112r2\n- secp128r1, secp128r2\n- secp160k1, secp160r1, secp160r2, brainpoolP160r1\n- secp192k1, prime192v1, brainpoolP192r1\n- secp224k1, secp224r1, brainpoolP224r1\n- secp256k1, prime256v1, brainpoolP256r1\n- brainpoolP320r1\n- secp384r1, brainpoolP384r1\n- brainpoolP512r1\n- secp521r1\n\nPlease tell me if you want to add any other curves.\n\n```python\nimport sslcrypto\n\n# Create curve object\ncurve = sslcrypto.ecc.get_curve(\"brainpoolP256r1\")\n\n# Generate private key, both compressed and uncompressed keys are supported\nprivate_key = curve.new_private_key(is_compressed=True)\n\n# Find a matching public key\npublic_key = curve.private_to_public(private_key)\n\n# If required, you can change public key format to whatever you want\nx, y = curve.decode_public_key(public_key)\nelectrum_public_key = x + y\n\n# Encrypt something. You can specify a cipher if you want to, aes-256-cbc is the\n# default value\ndata = b\"Hello, world!\"\nciphertext = curve.encrypt(data, public_key, algo=\"aes-256-ofb\")\n\n# Decrypt\nassert curve.decrypt(ciphertext, private_key, algo=\"aes-256-ofb\") == data\n```\n\n\n### ECDSA\n\n```python\nimport sslcrypto\n\n# Create curve object\ncurve = sslcrypto.ecc.get_curve(\"brainpoolP256r1\")\n\n# Generate private key\nprivate_key = curve.new_private_key()\n\n# Find a matching public key\npublic_key = curve.private_to_public(private_key)\n\n# Sign something\ndata = b\"Hello, world!\"\nsignature = curve.sign(data, private_key)\n\n# Verify\nassert curve.verify(signature, data, public_key) == True  # Would raise on error\n```\n\nAdditionally, you can create recoverable signatures:\n\n```python\nimport sslcrypto\n\n# Create curve object\ncurve = sslcrypto.ecc.get_curve(\"brainpoolP256r1\")\n\n# Generate private key\nprivate_key = curve.new_private_key()\n\n# Find a matching public key\npublic_key = curve.private_to_public(private_key)\n\n# Sign something\ndata = b\"Hello, world!\"\nsignature = curve.sign(data, private_key, recoverable=True)\n\n# Recover public key\nassert curve.recover(signature, data) == public_key  # Would raise on error\n```\n\n\n### Bitcoin-related functions\n\n```python\nimport sslcrypto\ncurve = sslcrypto.ecc.get_curve(\"secp256k1\")\nprivate_key = curve.new_private_key()\npublic_key = curve.private_to_public(private_key)\n\nwif = curve.private_to_wif(private_key)  # Transform to mainnet private key\nassert curve.wif_to_private(wif) == private_key\n\naddress = curve.private_to_address(private_key)\nassert address == curve.public_to_address(public_key)\n\n# Based on BIP32. Hardened indexes aren't supported yet\ncurve.child_derive(private_key, 123)\n```\n\n\n### Misc\n\n```python\nimport sslcrypto\nprint(sslcrypto.ecc.get_backend())  # Either \"fallback\" or OpenSSL info\n```\n\nYou can override OpenSSL path discovery:\n\n```python\nfrom sslcrypto.openssl import discovery\ndiscovery.discover = lambda: [\"openssl_lib.dll\"]\n```\n\nIf you want to go low-level, you can get curve parameters:\n\n```python\nimport sslcrypto\ncurve = sslcrypto.ecc.get_curve(\"secp256k1\")\nassert curve.params[\"n\"] == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141\n```\n\n\n## Running tests\n\nsslcrypto uses pytest framework. Install it with pip and run `python3 -m pytest\ntest` in sslcrypto repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurplesyringa%2Fsslcrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurplesyringa%2Fsslcrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurplesyringa%2Fsslcrypto/lists"}