Package: privy
Privy is a small and fast utility for password-protecting secret data such as
API keys, cryptocurrency wallets, or seeds for digital signatures.Table of ContentsUsageInstallationEncryption schemeEncrypted formatAPIhidepeekSecurity levelsLicenseChangelog6.0.05.0.04.0.03.0.02.0.11.0.0UsageSay for example you are using GnuPG. You are about to sign a message but it first
requires your password. Does your password become the input to instantiate your
private key? No, it is first hashed by a securekey derivation function. That
hash then becomes the input to a symmetric cipher such as AES which then decrypts
your stored private key. That is what Privy does.Fear not! With Privy, this become trivially easy:>>>importprivy>>>>>># After creating secret, immediately encrypt it using Privy.>>>data=b'secret'>>>>>>hidden=privy.hide(data,ask_for_password())>>>hidden'1$2$fL7xRh8WKe...'Now you can safely store or transmit the hidden secret. Whenever your user needs
to use their secret again, ask for their password to take a peek.>>>privy.peek(hidden,password)b'secret'InstallationPrivy is available on Linux/macOS and Windows and supports Python 2.7, 3.3+, PyPy, and PyPy3.3-5.5+.$pipinstallprivyEncryption schemeSecrets are encrypted using theFernetprotocol. Specifically, it uses AES for
encryption and has built-in authentication using HMAC. The private key used for
encryption is derived from the password using akey derivation function. The
key derivation function used isArgon2, the winner of thePassword Hashing
Competition. Both Argon2i and Argon2d variants are supported.Encrypted formatascii(Argon2 algorithm || security level || base64(salt) || base64(Fernet token))APIThere are 2 functions:hideandpeek.hidehide(secret, password, security=2, salt=None, server=True)Encryptssecretusingpassword. Returns the hidden secret as unicode.Parameterssecret(bytes) - The secret to encrypt.password(bytesorunicode) - The password used to access the secret.security(int) - A number 0-20 inclusive. Higher values are more secure at
the cost of slower computation and greater use of memory. Seesecurity levels.salt(bytes) - The salt used for the password hash. Defaults toos.urandom(32).server(bool) - IfTrue, it is assumed side-channel attack protection is
needed and therefore the Argon2i algorithm will be used. Otherwise, the password will
be hashed using the Argon2d algorithm.peekpeek(hidden, password, expires=None)Decryptshiddenusingpassword. Returns the secret asbytes.Parametershidden(bytesorunicode) - The hidden secret to decrypt.password(bytesorunicode) - The password used to access the secret.expires(int) - The maximum number of seconds since encryption that
is allowed. The default is no expiration.AValueErrorwill be raised if the password is wrong, the password was attempted on a
different hidden secret, or the number of seconds since encryption is >expiresargument.Security levelsAll expected times were taken from tests on an Intel Core i7-2670QM @ 2.2 GHz when decrypting
a 256 KiB secret.This is the command, whereSLis the desired security level:$python-mtimeit-s"import privy, os; pw = 'password'; s = os.urandom(1024 * 256); h = privy.hide(s, pw, SL)""privy.peek(h, pw)"LevelsArgon2 settingsExpected timeNotes0m=8 KiB, t=17 msecLowest possible1m=4 MiB, t=1054 msec2m=8 MiB, t=1099 msecDefault3m=32 MiB, t=10367 msec4m=48 MiB, t=10540 msec5m=96 MiB, t=101.1 secGood choice6m=256 MiB, t=103 sec7m=512 MiB, t=106 sec8m=768 MiB, t=109 sec9m=1 GiB, t=1012.2 sec10m=2 GiB, t=2048 secFor use on
users’ machines11m=3 GiB, t=3010712m=4 GiB, t=40?13m=5 GiB, t=50?14m=6 GiB, t=60?15m=7 GiB, t=70?16m=8 GiB, t=80?17m=9 GiB, t=90?18m=10 GiB, t=100?19m=11 GiB, t=110?20m=12 GiB, t=120?LicensePrivy is distributed under the terms of eitherMIT LicenseApache License, Version 2.0at your option.ChangelogImportant changes are emphasized.6.0.0Breaking:Support for Python 3.3 has been dropped.5.0.0Breaking:Privy is now dual-licensed under the terms of MIT and Apache v2.0.Only documented methodshideandpeekare now exposed in the root namespace.Travis now runs tests with the latest versions of PyPy and PyPy3.Improvements to documentation.4.0.0Breaking:For saner conformity, security level 7 now utilizes 512 MiB of RAM instead of 448.Major improvements to documentation.3.0.0Added security levels 11-20. These are quite resource intensive and are therefore
only acceptable for individual use.2.0.1Breaking:Due to requests, the encrypted format now uses url-safe base64 instead of hex.1.0.0Initial release