Crypto module - documentation?
I'd like to port a tiny application from PC to Pythonista/iOS in which I use the cryptography module to encrypt and decrypt text with a master password and a salt. My code works like this:
import base64 from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.backends import default_backend from cryptography.fernet import Fernet class SimpleCrypt: def __init__(self, password: str, salt: str): kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt.encode(), iterations=100000, backend=default_backend()) key = base64.urlsafe_b64encode(kdf.derive(password.encode())) self.fernet = Fernet(key) def encrypt(self, s: str): return self.fernet.encrypt(s.encode()).decode() def decrypt(self, s: str): return self.fernet.decrypt(s.encode()).decode()
Since the cryptography module is not available in Pythonista, I have now spend quite some time finding an alternative. Only thing I found is that there is obviously a "Crypto" module available in Pythonista which e.g. supports AES encryption, and indeed, I could import it in a test script. Nonetheless, there seems to be no documentation for this module (it is not even mentioned here: http://omz-software.com/pythonista/docs/py-modindex.html), so I am unsure about its capabilities.
Would be awesome if anyone has some more details about this Crypto module and could point me to its documentation for further reading.
Generally, if anyone has some tips for me how to port above code to make it run in Pythonista - I am all-ears :) Only requirement I have: Both implementations (PC and Pythonista) must be compatible, i.e., if I encrypt something with Pythonista, I should be able to decrypt it on the PC and vice versa (of course, using the same salt and password).
Many thanks upfront,
ccc last edited by ccc
Many thanks for your super-fast reply!
I must admit that I wasn't aware that Crypto == pycrypto. However, this is what I wanted to avoid - using a completely orphaned security-related module with unfixed vulnerabilities.... Anyway, will take a closer look and see if it fits my purposes nonetheless.
I am afraid I already know the answer, but maybe... besides pycrypt, there is currently no alternative way to perform symmetric encryption with Pythonista, right?
Again, many thanks!