Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document decrypt function #321

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ def create_decryptor(private_location, public_location):
public_file.write(pem)

def decrypt(ciphertext):
"""Decrypts a string that was encrypted user-side.

Example:

>>> from cryptography.hazmat.backends import default_backend
>>> from cryptography.hazmat.primitives import hashes
>>> from cryptography.hazmat.primitives.asymmetric import padding
>>> from cryptography.hazmat.primitives.serialization import load_pem_public_key
>>> pkey = load_pem_public_key(open("server/pubkey.txt", "rb").read(), default_backend())
>>> message = b"Hello, world!"
>>> encrypted = pkey.encrypt(message, padding.OAEP(
... padding.MGF1(hashes.SHA1()),
... hashes.SHA1(),
... None
... ))
>>> decrypt(encrypted)
b'Hello, world!'
"""
return private_key.decrypt(
ciphertext,
padding.OAEP(
Expand Down