Skip to content

Instantly share code, notes, and snippets.

@andymckay
Created February 11, 2020 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymckay/d8326a7125b119a2d836c7811c656327 to your computer and use it in GitHub Desktop.
Save andymckay/d8326a7125b119a2d836c7811c656327 to your computer and use it in GitHub Desktop.
from base64 import b64encode
from nacl import encoding, public
def encrypt(public_key: str, secret_value: str) -> str:
"""Encrypt a Unicode string using the public key."""
public_key = public.PublicKey(public_key.encode("utf-8"), encoding.Base64Encoder())
sealed_box = public.SealedBox(public_key)
encrypted = sealed_box.encrypt(secret_value.encode("utf-8"))
return b64encode(encrypted).decode("utf-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment