本文主要介绍 AES 算法的加解密方法。本文使用的语言为 C++,调用的 AES 库为:cryptopp。
1 概述
AES 加密算法的介绍如下(摘自 WikiPedia):
高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称 Rijndael 加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的 DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院(NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,AES 已然成为对称密钥加密中最流行的算法之一。
该算法为比利时密码学家 Joan Daemen 和 Vincent Rijmen 所设计,结合两位作者的名字,以 Rijndael 为名投稿高级加密标准的甄选流程。
2 cryptopp安装
cryptopp:Crypto++ Library is a free C++ class library of cryptographic schemes.
C++头文件GitHub地址:https://github.com/weidai11/cryptopp
C++头文件官方网站: https://cryptopp.com/
3 示例代码
本节介绍在 ECB 模式、16字节长度的 key、PKCS7填充方式的场景下,使用 AES 算法进行加解密的示例代码。
示例代码(aes_test1.cpp)如下: