Skip to content

Instantly share code, notes, and snippets.

@cygnusv
Last active March 20, 2018 08:50
Show Gist options
  • Save cygnusv/c7598de1873b1663242597fccc70b2a8 to your computer and use it in GitHub Desktop.
Save cygnusv/c7598de1873b1663242597fccc70b2a8 to your computer and use it in GitHub Desktop.
Basic example of pyUmbral
from umbral import umbral, keys
# Generate umbral keys for Alice.
alices_private_key = keys.UmbralPrivateKey.gen_key()
alices_public_key = private_key.get_pubkey()
# Generate umbral keys for Bob.
bobs_private_key = keys.UmbralPrivateKey.gen_key()
bobs_public_key = private_key.get_pubkey()
# Encrypt data with Alice’s public key.
plaintext = b'Proxy Re-encryption is cool!'
ciphertext, capsule = umbral.encrypt(alices_public_key, plaintext)
# Decrypt data with Alice’s private key.
cleartext = umbral.decrypt(capsule, alices_private_key, ciphertext, alices_public_key)
# Alice generates split re-encryption keys for Bob with “M of N”.
kfrags = umbral.split_rekey(alices_private_key, bobs_public_key, 10, 20)
# Ursula re-encrypts the capsule to obtain a cfrag.
# Bob attaches the cfrags to the capsule.
for kfrag in kfrags:
cfrag = umbral.reencrypt(kfrag, capsule)
capsule.attach_cfrag(cfrag)
# Bob opens the capsule.
cleartext = umbral.decrypt(ciphertext, capsule, bobs_private_key, alices_public_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment