{ "info": { "author": "Eric Wong", "author_email": "ericwong@zju.edu.cn", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Security", "Topic :: Security :: Cryptography", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "![version](https://img.shields.io/pypi/v/sm4.svg) ![license](https://img.shields.io/pypi/l/sm4.svg)\n\n# SM4\nA pure Python implementation for the famous SM4 algorithm, supporting Python 2 and 3.\n\n## Installation\nUsing `pip`:\n```bash\n$ pip install sm4 \n```\n\nOr manually download the archive and run the command after extracting the stuff inside:\n```bash\n$ python setup.py install\n```\n\n## Usage\nFirstly, define a `SM4Key` object by passing your encryption / decryption key. The key should be of length 16.\nNote that the key should be written as `bytes` in *Python 3*.\n```python\nfrom sm4 import SM4Key\nkey0 = SM4Key(b\"any length16 key\")\n```\n\nSecondly, encrypt messages by calling the method `encrypt()` from the `SM4Key` object, or decrypt them by calling `decrypt()`.\nNote that the messages should be written as `bytes` in *Python 3*.\n```python\nkey0.encrypt(b\"Any very very very long message!\") # -> b'\\x15\\x8a\\x18_qg\\xf4%\\x080\\xb2HEFFO\\x90\\x0e\\xc1\\xbb\\x07\\xe5\\xae\\xed\\xd5\\x90\\xf4K\\xfb\\xae]\\xae'\n```\n\nBy default, *ECB Mode* is used. You may enable *CBC Mode* by passing the argument `initial`, as the *Initial Value*.\nThe argument should be a `bytes` object of length 16. \n```python\nkey0.encrypt(b\"any long message\", initial=b\"\\0\"*16) # -> b'\\x15\\x8a\\x18_qg\\xf4%\\x080\\xb2HEFFO\\x98\\x01}1\\xe3\\xa5oL\\xdf\\x95(A\\xd8\\xce\\x14\\xc9'\n```\n\nThe *SM4* algorithm requires the message to be of any length that is a multiple of 16.\nBy default, the length of the message to encrypt / decrypt is assured by users.\nYou may choose to turn on *PKCS5 Padding Mode*(by passing the argument `padding` with a TRUTHY value), telling Python to do the padding before encryption for you.\n```python\nkey0.encrypt(b\"abc\", padding=True) # -> b'K\\x9euZ\\x03\\x96\\xe0\\x93+\\xc9%Z\\xab\\xf5\\xff\\x17'\n```\n\nWhile in decryption with *PKCS5 Padding*, the length of the message is still required to be a multiple of 8. But after decryption, Python will throw the padding characters away. \n```python\nkey0.decrypt(b\"K\\x9euZ\\x03\\x96\\xe0\\x93+\\xc9%Z\\xab\\xf5\\xff\\x17\", padding=True) # -> b\"abc\"\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/littlefisher/sm4", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sm4", "package_url": "https://pypi.org/project/sm4/", "platform": "", "project_url": "https://pypi.org/project/sm4/", "project_urls": { "Homepage": "https://github.com/littlefisher/sm4" }, "release_url": "https://pypi.org/project/sm4/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "A pure Python implementation for the SM4 algorithm", "version": "1.0.1" }, "last_serial": 5195969, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "bef8c08c09d20348b627ac3351efbb8d", "sha256": "697c9c37566a403eff13a558b7365adec4f5b4133d0f966488b11d7b66e0bf2d" }, "downloads": -1, "filename": "sm4-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bef8c08c09d20348b627ac3351efbb8d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4787, "upload_time": "2019-04-27T06:08:31", "url": "https://files.pythonhosted.org/packages/48/15/1552202e81b6bf3a482fae1e33c894678913c66f2816e07fa46908665db8/sm4-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "e11e3cfa97984f059225b81842530f67", "sha256": "96bc2fbcf6600b44024fef9413b65193024d4b701b6caf1656c40ef14bcf70f5" }, "downloads": -1, "filename": "sm4-1.0.1.tar.gz", "has_sig": false, "md5_digest": "e11e3cfa97984f059225b81842530f67", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4750, "upload_time": "2019-04-27T06:31:31", "url": "https://files.pythonhosted.org/packages/c9/a8/7cd75a1b902675e7af34a26c77b12155c0dd9f46a959ce629e20809697f3/sm4-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e11e3cfa97984f059225b81842530f67", "sha256": "96bc2fbcf6600b44024fef9413b65193024d4b701b6caf1656c40ef14bcf70f5" }, "downloads": -1, "filename": "sm4-1.0.1.tar.gz", "has_sig": false, "md5_digest": "e11e3cfa97984f059225b81842530f67", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4750, "upload_time": "2019-04-27T06:31:31", "url": "https://files.pythonhosted.org/packages/c9/a8/7cd75a1b902675e7af34a26c77b12155c0dd9f46a959ce629e20809697f3/sm4-1.0.1.tar.gz" } ] }