aes加密解密算法_加密-使用AES算法解密

aes加密解密算法

You can find plenty of algorithms on the Internet that provide the Encryption - Decryption functionality. One of them is the AES algorithm. AES stands for "Advanced Encryption Standard".

您可以在Internet上找到许多提供“加密-解密”功能的算法。 其中之一是AES算法。 AES代表“高级加密标准”。

The Advanced Encryption Standard was established by US National Institute of Standards and Technology in 2001. It was based; on the work of two Belgian cryptographers, Joan Daemen and Vincent Rijmen, who submitted the proposal to NIST during the selection process.

高级加密标准是由美国国家标准技术研究院于2001年建立的。 关于两位比利时密码学家Joan Daemen和Vincent Rijmen的工作,他们在选择过程中向NIST提交了该建议。

In the AES algorithm, there is a terminology we use called 'Cipher Mode'. There are different types Cipher Modes present in the algorithm. Based on your specific needs and requirements you can select the Cipher Modes. Let's have a look at what these are and how they differentiate from other cipher modes.

在AES算法中,有一种我们称为“密码模式”的术语。 算法中存在不同类型的密码模式。 根据您的特定需求和要求,您可以选择密码模式。 让我们看看它们是什么以及它们与其他密码模式的区别。

1. Electronic Code Book Mode: This mode doesn't require any feedback to be applied. You pass the plain text/data using this and and get the resulted Cipher data from it directly. The main disadvantage is that this mode will return the same cipher data on passing the same type of plain text in loop; if you pass 'Hello, World!' three times in this mode then it will return same cipher data in each iteration. That is why this mode is considered as 'Vulnerable' and not recommended for use.

1.电子密码簿模式:此模式不需要任何反馈。 您使用此方法传递纯文本/数据,然后直接从中获取生成的密码数据。 主要缺点是,此模式在循环传递相同类型的纯文本时将返回相同的密码数据。 如果您通过“你好,世界!” 在这种模式下,它将重复三次,则每次迭代将返回相同的密码数据。 这就是为什么将此模式视为“易受攻击的”而不推荐使用的原因。

2. Cipher Block Chaining Mode: This mode is required to add the feeback to modify the pre-encrypted data; with the feedback it will make each cipher data different from previous re

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用python的cryptography库来实现AES加密解密,以及使用zeropadding进行填充。 首先,你需要安装cryptography库。可以使用以下命令来安装: ``` pip install cryptography ``` 接下来,你可以使用以下代码示例来实现AES加密解密,并使用zeropadding进行填充: ```python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives import padding from cryptography.hazmat.backends import default_backend import os def aes_encrypt(plain_text, key): # 生成一个随机的初始化向量 iv = os.urandom(16) # 使用zeropadding进行填充 padder = padding.ZeroPadding(128).padder() padded_data = padder.update(plain_text) + padder.finalize() # 创建AES加密器对象 cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend()) encryptor = cipher.encryptor() # 执行加密操作 cipher_text = encryptor.update(padded_data) + encryptor.finalize() return iv + cipher_text def aes_decrypt(cipher_text, key): # 提取初始化向量和密文 iv = cipher_text[:16] cipher_text = cipher_text[16:] # 创建AES解密器对象 cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend()) decryptor = cipher.decryptor() # 执行解密操作 padded_data = decryptor.update(cipher_text) + decryptor.finalize() # 使用zeropadding进行取消填充 unpadder = padding.ZeroPadding(128).unpadder() plain_text = unpadder.update(padded_data) + unpadder.finalize() return plain_text # 测试代码 key = os.urandom(32) # 生成一个随机密钥 plain_text = b"Hello, AES!" # 原始文本 # 加密 cipher_text = aes_encrypt(plain_text, key) print("Cipher Text: ", cipher_text) # 解密 decrypted_text = aes_decrypt(cipher_text, key) print("Decrypted Text: ", decrypted_text) ``` 这段代码中,我们使用AES加密算法和CBC模式来加密解密数据。同时,我们使用了zeropadding进行填充,确保数据长度满足加密算法的要求。需要注意的是,密钥的长度必须符合AES算法的要求(16、24、或32字节)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值