Differenze tra le versioni di "Crittografia in Python"
(Creata pagina con "← Python Category:Python fonte: https://blog.finxter.com/how-to-encrypt-and-decrypt-python-strings/#:~:text=To%20encrypt%20and%20decrypt%20a,decr...") |
|||
| Riga 1: | Riga 1: | ||
[[GENERALE#Python|← Python]] [[Category:Python]] | [[GENERALE#Python|← Python]] [[Category:Python]] | ||
| − | fonte: https://blog.finxter.com/how-to-encrypt-and-decrypt-python-strings/ | + | fonte: https://blog.finxter.com/how-to-encrypt-and-decrypt-python-strings/ |
== Pacchetti necessari == | == Pacchetti necessari == | ||
Versione attuale delle 10:26, 29 nov 2023
fonte: https://blog.finxter.com/how-to-encrypt-and-decrypt-python-strings/
Pacchetti necessari
- cryptography
pip install cryptography
Esempio
# Import the cryptography library
from cryptography.fernet import Fernet
# Generate a Fernet key
key = Fernet.generate_key()
# Create a Fernet object with that key
f = Fernet(key)
# Input string to be encrypted
input_string = "Hello World!"
# Encrypt the string
encrypted_string = f.encrypt(input_string.encode())
# Decrypt the encrypted string
decrypted_string = f.decrypt(encrypted_string)
# Print the original and decrypted strings
print("Original String:", input_string)
print("Decrypted String:", decrypted_string.decode())