Computer Security
Computer security involves protecting computer systems and data from unauthorized access, theft, and damage. Understanding computer security is essential for developing software that is secure and resilient to attacks. Here's an example of a simple security program in Python using the cryptography library:
from cryptography.fernet import Fernet
# Generate a key
key = Fernet.generate_key()
# Store the key in a file
with open('key.txt', 'wb') as f:
f.write(key)
# Load the key from the file
with open('key.txt', 'rb') as f:
key = f.read()
# Create a Fernet object with the key
cipher = Fernet(key)
# Encrypt a message
message = b'Hello, world!'
encrypted_message = cipher.encrypt(message)
print('Encrypted message:', encrypted_message)
# Decrypt the message
decrypted_message = cipher.decrypt(encrypted_message)
print('Decrypted message:', decrypted_message)
No comments:
Post a Comment