C++利用Crypto++,vs2005环境下的RSA应用

——————————————————说明:部分内容参考网上现有。————————————————--

——————此文适合新手入门,大神直接飞过————————

————感想,可跳过哈 ,^_^————

这几天老师要求做一个关于rsa加密的项目,要求加解密文本内容。主要遇到密钥生成、待加解密字符串过长等遇到问题,下面会一一解决。网上查看资料大多是每次都生成新的密钥,而且加密的明文较短,所以第一次有了写博客的冲动哈!~~~~~

—————进入主题 !  ———————


一、crypto++sdk,环境及项目的配置,参照:http://www.cnblogs.com/cxun/archive/2008/07/30/743541.html

二、生成固定密钥,参照crypto++官方文档:http://www.cryptopp.com/wiki/Keys_and_Formats#Generating.2C_Validating.2C_Saving.2C_and_Loading_Keys

        所用代码示例也为官方sample,稍稍改动了一点点,在代码中会有说明。(别被吓唬了,其实慢慢看还是很容易的)

       必须现在c盘建一个rsa05的文件夹,否则会出错。出错点在下面代码中有标注。(之前没有建立这个文件夹,程序会中断抛出异常。)

#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

#include <string>
using std::string;

#include <stdexcept>
using std::runtime_error;

#include <queue.h>
using CryptoPP::ByteQueue;

#include "filters.h"
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::PK_EncryptorFilter;
using CryptoPP::PK_DecryptorFilter;

#include <files.h>
using CryptoPP::FileSource;
using CryptoPP::FileSink;

#include "dsa.h"
using CryptoPP::DSA;

#include "rsa.h"
using CryptoPP::RSA;
using CryptoPP::InvertibleRSAFunction;
using CryptoPP::RSAES_OAEP_SHA_Encryptor;
using CryptoPP::RSAES_OAEP_SHA_Decryptor;

#include <cryptlib.h>
using CryptoPP::PrivateKey;
using CryptoPP::PublicKey;
using CryptoPP::BufferedTransformation;

#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;


#pragma comment(lib, "cryptlib.lib");

void EncodePrivateKey(const string& filename, const RSA::PrivateKey& key);
void EncodePublicKey(const string& filename, const RSA::PublicKey& key);
void Encode(const string& filename, const BufferedTransformation& bt);

void DecodePrivateKey(const string& filename, RSA::PrivateKey& key);
void DecodePublicKey(const string& filenam
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值