from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, PublicFormat, NoEncryption
class ECCEncryption:
def init(self):
self.private_key = ec.generate_private_key(ec.SECP256R1())
self.public_key = self.private_key.public_key()
ecc_encryption = ECCEncryption()
peer_public_key = ecc_encryption.get_public_key() # In real scenarios, this would be provided by the peer
shared_key = ecc_encryption.encrypt("Sensitive Data", peer_public_key)
print(f"Shared Key: {shared_key}")
Combine RSA and AES
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
RSA Encryption
from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP from Crypto.Random import get_random_bytes
class RSAEncryption: def init(self): self.key = RSA.generate(2048) self.public_key = self.key.publickey()
Example usage
rsa_encryption = RSAEncryption() encrypted_data = rsa_encryption.encrypt("Sensitive Data") decrypted_data = rsa_encryption.decrypt(encrypted_data)
print(f"Encrypted Data: {encrypted_data}") print(f"Decrypted Data: {decrypted_data}")
ECC
from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.primitives.kdf.hkdf import HKDF from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, PublicFormat, NoEncryption
class ECCEncryption: def init(self): self.private_key = ec.generate_private_key(ec.SECP256R1()) self.public_key = self.private_key.public_key()
Example usage
ecc_encryption = ECCEncryption() peer_public_key = ecc_encryption.get_public_key() # In real scenarios, this would be provided by the peer shared_key = ecc_encryption.encrypt("Sensitive Data", peer_public_key)
print(f"Shared Key: {shared_key}")
Combine RSA and AES
from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad
class HybridEncryption: def init(self): self.rsa_encryption = RSAEncryption() self.aes_key = get_random_bytes(32) # AES-256 key
Example usage
hybrid_encryption = HybridEncryption() encrypted_aes_key, iv, encrypted_data = hybrid_encryption.encrypt("Sensitive Data") decrypted_data = hybrid_encryption.decrypt(encrypted_aes_key, iv, encrypted_data)
print(f"Encrypted AES Key: {encrypted_aes_key}") print(f"Encrypted Data: {encrypted_data}") print(f"Decrypted Data: {decrypted_data}")