Skip to main content

A straightforward API to perform basic RSA-based operations..

Project description

Simple RSA

A straightforward API to perform basic RSA-based operations.

Latest Version on PyPI Supported Implementations Build Status Coverage Status Built with PyPi Template

Rationale

Any cryptographic library exposes all possibilities, and it should. But sometimes you just want a simple sign and validate API. That is what this wrapper module around the Cryptography module is. Nothing more, nothing less.

Getting Started

The module basically exposes the following functions:

  • generate_key_pair() returning a tuple of private and public keys
  • encode(key) returning an encoded key
  • decode(pem) returning a key
  • sign(payload, key) returning a signature
  • validate(payload, signature, key) returning True or an Exception
$ python
Python 2.7.15 (default, Dec 27 2018, 11:55:59) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import simple_rsa as rsa
>>> private, public = rsa.generate_key_pair()
>>> rsa.encode(public)
'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5C15SFjpTCrdqB+0zFyu\nC9KJkNT1byzQPyATtLze/PNWjfqYL0RjvL4cmvmBWLeTQvnDx9SQfnQT02+4Q8Ov\nOaRTPqghEJctAh7KHwZfQzH29miC1WxXtGFcMFoAj17WPyMaOO3EcHqb4ttnAAPD\nt6B415HtGZo4oH6xY7QMj4eRceTv4++zACNHvqArO3bFFiNTBC8vCOpIg3xsYV4w\n7lQZs2lwGlzXPFJUeZglvsWTPJ54E1KabtkC/wSRFZBYtml8ZvzFfNDTOhcDyBR9\nVTV4K7iIGXG0A9C7mmj3hgALS3qSP5EK6fi51ufg98WokCLFcTSD/EphUlixazPo\nOQIDAQAB\n-----END PUBLIC KEY-----\n'
>>> payload = b"something important"
>>> signature = rsa.sign(payload, private)
>>> assert rsa.validate(payload, signature, public)
>>> another_payload = b"something else"
>>> another_signature = rsa.sign(another_payload, private)
>>> assert rsa.validate(payload, another_signature, public)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "simple_rsa/__init__.py", line 74, in validate
    hashes.SHA256()
  File "/usr/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 477, in verify
    self._backend, padding, algorithm, self, signature, data
  File "/usr/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 272, in _rsa_sig_verify
    raise InvalidSignature
cryptography.exceptions.InvalidSignature

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-rsa-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

simple_rsa-1.0.0-py2-none-any.whl (4.4 kB view details)

Uploaded Python 2

File details

Details for the file simple-rsa-1.0.0.tar.gz.

File metadata

  • Download URL: simple-rsa-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for simple-rsa-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffb04e82a30bedbd2da262beec2d8e0de3ad72f71af50ae46bdb650b01403eb8
MD5 e4ff061ae69f89087006d8410b6ad724
BLAKE2b-256 65a91cb1d582fa98727450316160bc7812a0d8b47562b27fdf90a925cc7f0651

See more details on using hashes here.

File details

Details for the file simple_rsa-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: simple_rsa-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for simple_rsa-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 27b9c8de5fc2308f3f48ee61f28a132ae5d4e56cfddb78cb383293ccf5d7d7d9
MD5 91cf48dd1f856294c531fd47aa402a57
BLAKE2b-256 a9957070c9b0bd69cb5242b0e7a8c535b89eb8b0801b60474bb9130981143a23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page