Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Cryptographic utility function for encrypting and decrypting messages
ResourceFunction["Fernet"]["GenerateKey"] generates a key for use with Fernet encryption and decryption. | |
ResourceFunction["Fernet"][{"Encrypt",key},message] encrypts message using key. | |
ResourceFunction["Fernet"][{"Decrypt",key},data] decrypts data using key. |
Generate a cryptographic key for use with Fernet:
| In[1]:= |
| Out[1]= |
Encrypt a message using the cryptographic key:
| In[2]:= |
| Out[2]= |
The encrypted data has a "BASE64" compatible string format, so it can be used in URL requests:
| In[3]:= |
| Out[3]= |
Decrypt the message with the same key:
| In[4]:= |
| Out[4]= |
You can only decrypt data with the original Fernet key:
| In[5]:= | ![]() |
| Out[4]= |
You can not use arbitrary byte arrays as the encryption key:
| In[6]:= |
| Out[6]= | ![]() |
Generated keys should be stored securely. One method of secure persistent storage is provided by SystemCredential:
| In[7]:= | ![]() |
| Out[9]= |
Encrypt using the key stored in SystemCredential:
| In[10]:= |
| Out[10]= |
Decrypt using the key stored in SystemCredential:
| In[11]:= |
| Out[11]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License