以太网解密动图

224 篇文章 3 订阅

网上QQ找出来的以太网的事例:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python本身并不提供以太网加密解密的功能,但可以使用第三方库来实现。其中比较常用的是pycryptodome和cryptography库。 使用pycryptodome库进行以太网加密解密的示例代码如下: ```python from Crypto.Cipher import AES # 加密 def encrypt(key, plaintext): cipher = AES.new(key, AES.MODE_EAX) ciphertext, tag = cipher.encrypt_and_digest(plaintext.encode()) return ciphertext, cipher.nonce, tag # 解密 def decrypt(key, nonce, ciphertext, tag): cipher = AES.new(key, AES.MODE_EAX, nonce=nonce) plaintext = cipher.decrypt_and_verify(ciphertext, tag) return plaintext.decode() ``` 其中,key为加密密钥,plaintext为明文,ciphertext为密文,nonce为随机数,tag为认证标签。 使用cryptography库进行以太网加密解密的示例代码如下: ```python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding # 加密 def encrypt(key, plaintext): iv = os.urandom(16) cipher = Cipher(algorithms.AES(key), modes.CBC(iv)) encryptor = cipher.encryptor() padder = padding.PKCS7(128).padder() padded_plaintext = padder.update(plaintext.encode()) + padder.finalize() ciphertext = encryptor.update(padded_plaintext) + encryptor.finalize() return ciphertext, iv # 解密 def decrypt(key, iv, ciphertext): cipher = Cipher(algorithms.AES(key), modes.CBC(iv)) decryptor = cipher.decryptor() padded_plaintext = decryptor.update(ciphertext) + decryptor.finalize() unpadder = padding.PKCS7(128).unpadder() plaintext = unpadder.update(padded_plaintext) + unpadder.finalize() return plaintext.decode() ``` 其中,key为加密密钥,plaintext为明文,ciphertext为密文,iv为初始化向量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值