Crypto++学习总结---AES
2015-11-20 16:01
441 查看
静态库下载连接Cryp++ lib 下载
AES 使用方法 如下:
[cpp] view
plaincopy
//For AES encrypt
#include "default.h"
#include "cryptlib.h"
#include "filters.h"
#include "bench.h"
#include "osrng.h"
#include "hex.h"
#include "modes.h"
#include "files.h"
using namespace CryptoPP;
#pragma comment(lib, "cryptopp\\lib\\cryptlib.lib")
using namespace std;
void main() {
unsigned char key[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, 0x01,0x02, 0x03,0x04,0x05,0x06,0x07,0x08};//AES::DEFAULT_KEYLENGTH
unsigned char iv[] = {0x01,0x02,0x03,0x03,0x03,0x03,0x03,0x03, 0x03,0x03, 0x01,0x02,0x03,0x03,0x03,0x03};
int keysize = 16;
string message = "Hello World!";
string strEncTxt;
string strDecTxt;
//CBC - PADDING
//AES-CBC Encrypt(ONE_AND_ZEROS_PADDING)
CBC_Mode<AES>::Encryption Encryptor1(key,keysize,iv);
StringSource( message,
true,
new StreamTransformationFilter( Encryptor1,
new StringSink( strEncTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::ONE_AND_ZEROS_PADDING,
true)
);
//AES-CBC Decrypt
CBC_Mode<AES>::Decryption Decryptor1(key,keysize,iv);
StringSource( strEncTxt,
true,
new StreamTransformationFilter( Decryptor1,
new StringSink( strDecTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::ONE_AND_ZEROS_PADDING,
true)
);
//CTR - NO_PADDING
//AES-CTR Encrypt
CTR_Mode<AES>::Encryption Encryptor2(key,keysize,iv);
StringSource( message,
true,
new StreamTransformationFilter( Encryptor2,
new StringSink( strEncTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::NO_PADDING,
true)
);
//AES-CTR Decrypt
CTR_Mode<AES>::Decryption Decryptor2(key,keysize,iv);
StringSource( strEncTxt,
true,
new StreamTransformationFilter( Decryptor2,
new StringSink( strDecTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::NO_PADDING,
true)
);
}
AES 使用方法 如下:
[cpp] view
plaincopy
//For AES encrypt
#include "default.h"
#include "cryptlib.h"
#include "filters.h"
#include "bench.h"
#include "osrng.h"
#include "hex.h"
#include "modes.h"
#include "files.h"
using namespace CryptoPP;
#pragma comment(lib, "cryptopp\\lib\\cryptlib.lib")
using namespace std;
void main() {
unsigned char key[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, 0x01,0x02, 0x03,0x04,0x05,0x06,0x07,0x08};//AES::DEFAULT_KEYLENGTH
unsigned char iv[] = {0x01,0x02,0x03,0x03,0x03,0x03,0x03,0x03, 0x03,0x03, 0x01,0x02,0x03,0x03,0x03,0x03};
int keysize = 16;
string message = "Hello World!";
string strEncTxt;
string strDecTxt;
//CBC - PADDING
//AES-CBC Encrypt(ONE_AND_ZEROS_PADDING)
CBC_Mode<AES>::Encryption Encryptor1(key,keysize,iv);
StringSource( message,
true,
new StreamTransformationFilter( Encryptor1,
new StringSink( strEncTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::ONE_AND_ZEROS_PADDING,
true)
);
//AES-CBC Decrypt
CBC_Mode<AES>::Decryption Decryptor1(key,keysize,iv);
StringSource( strEncTxt,
true,
new StreamTransformationFilter( Decryptor1,
new StringSink( strDecTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::ONE_AND_ZEROS_PADDING,
true)
);
//CTR - NO_PADDING
//AES-CTR Encrypt
CTR_Mode<AES>::Encryption Encryptor2(key,keysize,iv);
StringSource( message,
true,
new StreamTransformationFilter( Encryptor2,
new StringSink( strEncTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::NO_PADDING,
true)
);
//AES-CTR Decrypt
CTR_Mode<AES>::Decryption Decryptor2(key,keysize,iv);
StringSource( strEncTxt,
true,
new StreamTransformationFilter( Decryptor2,
new StringSink( strDecTxt ),
BlockPaddingSchemeDef::BlockPaddingScheme::NO_PADDING,
true)
);
}
相关文章推荐
- Android Service AIDL
- crontab无法调用java的问题解决
- 前端学习网址
- 深入理解C++中的mutable关键字
- Unity3D中切换场景可能导致材质变暗的问题
- I.MX6 I2C DS1337 disable square-wave output
- 实验3.1
- 从TCP协议的原理来谈谈rst复位攻击
- 往resin 服务器中发送post 报 POST requires content-length
- 网络通信
- 哈夫曼树
- 【Win 10应用开发】延迟加载图片的另一种方法
- 继续减税,赤字才有含金量
- kong 在Linux下操作
- Android 内存分析
- JS 把数字转换成字母
- IOS学习——Navigation Controller
- 通过HBase Observer同步数据到ElasticSearch
- 辛星浅析nodejs中的MySQL连接池
- 简易图片查看器