Skip to main content

PyPi version Travis build

This is an implementation of Boldyreva symmetric order-preserving encryption scheme (Boldyreva’s paper).

Supported Python versions: 2.7 and 3.4+

Disclaimer 1 This is an experimental implementation, which should be thoroughly reviewed and evaluated before using in production and/or sensitive applications.

Disclaimer 2 The Boldyreva scheme is not a standardized algorithm, so there are no test vectors and fixed plaintext-ciphertext mapping for a given key. It means that, generally speaking, a plaintext encrypted with the same key by two different versions of the package might not be equal to each other.

Quick examples

Quick start

from pyope.ope import OPE
random_key = OPE.generate_key()
cipher = OPE(random_key)
assert cipher.encrypt(1000) < cipher.encrypt(2000) < cipher.encrypt(3000)
assert cipher.decrypt(cipher.encrypt(1337)) == 1337

You can specify input and output ranges. Otherwise, default input (0..2^15-1) and output (0..2^31-1) ranges are used.

from pyope.ope import OPE, ValueRange
cipher = OPE(b'long key' * 2, in_range=ValueRange(-100, 100),
                              out_range=ValueRange(0, 9999))
assert 0 < cipher.encrypt(10) < cipher.encrypt(42) < 9999

About order-preserving encryption

Order-preserving encryption (OPE) allows to compare ciphertext values in order to learn the corresponding relation between the underlying plaintexts. By definition, order-preserving encryption methods are less secure than conventional encryption algorithms for the same data sizes, because the former leak ordering information of the plaintext values.

How can OPE be useful? For example, some systems may need OPE to perform a certain set of queries (such as range SQL queries) over encrypted data. These systems include CryptDB and Monomi to name a few.

Security

As mentioned above, security guarantees for Boldyreva’s schema are weaker than those of deterministic encryption schemes, but security can still be improved if the encryption keys are long enough. It is advised to use randomly generated keys at least 256 bits long.

Running tests

PyTest is used as a test framework. Run all tests:

$ py.test tests/

TODO

  • More tests

  • Optimize performance

  • Security guarantees?

History

0.1.0 (2017-01-01)

  • Use ‘cryptography’ instead of ‘pycrypto’

Release files for pyope 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyope 0.2.2
File Size Uploaded
pyope-0.2.2.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyope 0.2.2
File Interpreter ABI Platform
pyope-0.2.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size:21.5 kB

Release files / pyope-0.2.2.tar.gz

Download URL pyope-0.2.2.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
58b55738212b54c78a1a192f014e7fa9d693d970d260238f76803fa87f49af3c
BLAKE2b-256 checksum
How to use checksums
eebb67e2b2822ad3dc1bcb6af471685ce3a35d3b3d3581e8d14468da0fc9dec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / pyope-0.2.2-py2.py3-none-any.whl

Download URL pyope-0.2.2-py2.py3-none-any.whl
Size 11.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
45f71fdc1b3a4b6c97232be71d6b05218bf09d84bf2dc5ec09f76038fbbf1c61
BLAKE2b-256 checksum
How to use checksums
64a845506e7ce0843a31c49ed5f2e7e2f76cdb7992664c3b4448fe3077cfd482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page