Crypto++ RSA从字符串读取公私匙
string and StringSource (load):
string spki = ...;
StringSource ss(spki, true /*pumpAll*/); RSA::PublicKey publicKey;
publicKey.Load(ss);
vector and ArraySource (load):
vector<byte> spki = ...;
ArraySource as(&spki[0], spki.length(), true /*pumpAll*/); RSA::PublicKey publicKey;
publicKey.Load(as);
string and StringSink (save)
string spki;
StringSink ss(spki); RSA::PublicKey publicKey(...);
publicKey.Save(ss);
vector (save)
Below is an example of saving to and loading from a std::vector. You have to use an intermediate ByteQueue to save because you can't easily create a VectorSink.
AutoSeededRandomPool prng;
RSA::PrivateKey pk1, pk2; pk1.Initialize(prng, 1024);
ByteQueue queue;
pk1.Save(queue); vector<byte> spki;
spki.resize(queue.MaxRetrievable()); ArraySink as1(&spki[0], spki.size());
queue.CopyTo(as1); ArraySource as2(&spki[0], spki.size(), true);
pk2.Load(as2); bool valid = pk2.Validate(prng, 3);
if(valid)
cout << "Validated private key" << endl;
else
cout << "Failed to validate private key" << endl;
We don't have an explicit VectorSink, and we can't easily create one because of an implicit expectation of traits_type::char_type. For example:
using CryptoPP::StringSinkTemplate;
typedef StringSinkTemplate< std::vector<byte> > VectorSink; In file included from cryptopp-test.cpp:65:
In file included from /usr/local/include/cryptopp/files.h:5:
/usr/local/include/cryptopp/filters.h:590:22: error: no member named
'traits_type' in 'std::vector<unsigned char, std::allocator<unsigned char>
>'
typedef typename T::traits_type::char_type char_type;
~~~^
cryptopp-test.cpp:243:20: note: in instantiation of template class
'CryptoPP::StringSinkTemplate<std::vector<unsigned char,
std::allocator<unsigned char> > >' requested here
VectorSink vs(spki);
http://c/questions/29050575/how-would-i-load-a-private-public-key-from-a-string-byte-array-or-any-other
Crypto++ RSA从字符串读取公私匙的更多相关文章
- [转]C# JSON格式的字符串读取到类中
将JSON格式的字符串读取到类中 本例中建立JSON格式的字符串json,将其内容读取到Person类中 运行本代码需要添加引用动态库Newtonsoft.Json 程序代码: using Syste ...
- C++ Crypto++ RSA加密资料收集
C++利用Crypto++,vs2005环境下的RSA应用 基于Crypto++/Cryptopp的rsa密钥生成,rsa加密.解密,rsa签名.验签 Keys and Formats 使用Crypt ...
- 题目1029:魔咒词典(map使用以及字符串读取函数总结)
题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...
- C语言:字符串读取流读取文件中的数据
#include<stdio.h> int main() { //定义文件指针 FILE *f = NULL; //打开文件 f = fopen("1.txt",&qu ...
- mac生成ssh公私匙
1. cd ~/.ssh/ 2.ssh-keygen 3.id_rsa.pub文件放入git 4.私匙放进jenkins
- C语言:使用命令行参数用字符串读取流和输出流进行文本文件的复制
#include<stdio.h> int main(int argc,char *argv[]) { //检查用户的参数是否正确 if(argc<3) { printf(" ...
- 基于Crypto++的aes 字符串加解密实现
esaes.h: #ifndef ESAES_H #define ESAES_H #include <cryptopp/aes.h> #include <iostream> # ...
- php字符串读取函数
function cc_msubstr($str, $length, $start=0, $charset="utf-8", $suffix=true){ if(function_ ...
- 加密webconfig中的连接字符串,利用RSA非对称加密,利用windows保存密钥容器
简单的解决方法: WebConfig 加解密,未能使用提供程序“RsaProtectedConfigurationProvider”进行解密.提供程序返回错误消息为: 打不开 RSA 密钥容器.问题: ...
随机推荐
- Activity的Launch Mode
ANDROID四种启动模式: 1.standard:默认的启动模式,每次新建一个实例对象. 2.singleTop:如果在任务栈顶发现了相同的实例则复用该实例,否则新建一个实例并压入栈顶. 3.sin ...
- UE4 Windows平台部署游戏到IOS 第一部分
UE4 Version 4.11.2 or 4.12.2 方法步骤: 1.申请IOS开发者账号,大概三个工作日左右激活. 2.下载iTunes 3.创建项目因为是在Windows平台,根据官方的提示只 ...
- PHP character garbled
MySql 控制台查询时出现乱码 Database&Table 的字符集 于Mysql控制台显示的字符集不一样 右键单击mysql控制台边框 单击属性 查看当前代码页的字符集模式是否于数 ...
- cookie单点登录(跨域访问)
新近一家公司上来就让做oa,要求嵌入公司现有系统模块,自然而然想到模拟post单点登录对方系统新建单点登陆页面保存session,然现有系统都有用cookie保存用户信息,故保存本地cookie……测 ...
- mysql 根据某字段特定值排序
比如: 表 :user 字段:orders (值为 1,2,3) 要求根据字段 orders 按2 -> 1 -> 3 排序 使用以下语句实现SELECT *FROM userORDER ...
- Git标签和别名管理
一.Git标签管理 标签类似于快照功能,可以给版本库打一个标签,记录某个时刻库的状态,也可以随时恢复到该状态 例如给master打一个v1.0的标签 先切换到master分支上去git checkou ...
- JSON.parse() 和 JSON.stringify()
JSON.parse()和JSON.stringify() 1.parse 用于从一个字符串中解析出json 对象.例如 var str='{"name":"cpf& ...
- ASP.NET(转自wiki)
ASP.NET是由微软在.NET Framework框架中所提供,开发Web应用程序的类库,封装在System.Web.dll文件中,显露出System.Web名字空间,并提供ASP.NET网页处理. ...
- golang开发环境(2016.9.16)
一.windows下安装 1.下载go1.7.3.windows-amd64.msi,建议默认安装到‘C:\Go\’ 2.环境变量 变量 值 说明 Path C:\Go\bin 安装程序默认会设置,如 ...
- jdbc/DAO模式
DAO设计模式: 1.DAO: DAO设计模式是属于J2EE数据层的操作,使用DAO设计模式可以简化大量代码,增强程序的可移植性. 2.DAO各部分详解:DAO设计模式包括以下4个主要部分: ...