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从字符串读取公私匙的更多相关文章

  1. [转]C# JSON格式的字符串读取到类中

    将JSON格式的字符串读取到类中 本例中建立JSON格式的字符串json,将其内容读取到Person类中 运行本代码需要添加引用动态库Newtonsoft.Json 程序代码: using Syste ...

  2. C++ Crypto++ RSA加密资料收集

    C++利用Crypto++,vs2005环境下的RSA应用 基于Crypto++/Cryptopp的rsa密钥生成,rsa加密.解密,rsa签名.验签 Keys and Formats 使用Crypt ...

  3. 题目1029:魔咒词典(map使用以及字符串读取函数总结)

    题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...

  4. C语言:字符串读取流读取文件中的数据

    #include<stdio.h> int main() { //定义文件指针 FILE *f = NULL; //打开文件 f = fopen("1.txt",&qu ...

  5. mac生成ssh公私匙

    1. cd ~/.ssh/ 2.ssh-keygen 3.id_rsa.pub文件放入git 4.私匙放进jenkins

  6. C语言:使用命令行参数用字符串读取流和输出流进行文本文件的复制

    #include<stdio.h> int main(int argc,char *argv[]) { //检查用户的参数是否正确 if(argc<3) { printf(" ...

  7. 基于Crypto++的aes 字符串加解密实现

    esaes.h: #ifndef ESAES_H #define ESAES_H #include <cryptopp/aes.h> #include <iostream> # ...

  8. php字符串读取函数

    function cc_msubstr($str, $length, $start=0, $charset="utf-8", $suffix=true){ if(function_ ...

  9. 加密webconfig中的连接字符串,利用RSA非对称加密,利用windows保存密钥容器

    简单的解决方法: WebConfig 加解密,未能使用提供程序“RsaProtectedConfigurationProvider”进行解密.提供程序返回错误消息为: 打不开 RSA 密钥容器.问题: ...

随机推荐

  1. JS对象实现随机满天小星星实例

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. github:如何获取项目源代码

    github是流行的源码管理平台.这上面有很多开源的项目.作为普通的用户,如何获取这些开源项目的源码呢? 1.首先需要注册一个github账号. 2.安装windows下的git工具:下载地址: ht ...

  3. HDU1532 网络流:最大流之福德福克森算法

    问题描述:约翰是个农民,每次下雨的时候他的庄家总是会被淹没,这就意味着当庄家被水淹后需要很长时间才能重新生长出来,因此,约翰已经建立了一系列排水管道为了使他的庄家尽可能被淹没的最少,也就是说管道的排水 ...

  4. Hello Docker (Docker 入门分享)

    Hello Docker 1 PPT @ http://download.csdn.net/download/liangread/9431056 TBD

  5. Flat UI 工具包

    Flat UI是一套精美的扁平风格 UI 工具包,基于 Twitter Bootstrap 实现.这套界面工具包含许多基本的和复杂的 UI 部件,例如按钮,输入框,组合按钮,复选框,单选按钮,标签,菜 ...

  6. mfc 调用Windows的API函数实现同步异步串口通信(源码)

    在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...

  7. ubuntukylin14安装ns-allinone-2.35教程(虚拟机ubuntu同理)

    准备材料: 1.ubuntukylin14,百度进官网自行下载: 2.ns-allinone-2.35.tar.gz,百度进官网自行下载: 3.虚拟机:vmwareworkstation(可选). 4 ...

  8. OpenCV学习笔记——OpenCV安装

    关于OpenCV安装 1.下载和安装OpenCV SDK 在官网:http://opencv.org/上找到OpenCV windows版下载 . 后得到一个 opencv-2.X.X.exe的文件, ...

  9. Redis -- 02 配置文件解析

    redis的配置文件为 redis.conf, 使用 ./redis-server /path/to/redis.conf 可以根据自定义的配置启动redis实例 include // 引入其他配置文 ...

  10. DSP中.gel文件的作用

    GEL是CCS提供的一种解释语言,使用该语言写出的GEL,函数具有两在功能,一是配置CCS工作环境,二是直接访问目标处理器DSP(包括DSP软/硬仿真器).用户可以使用GEL函数完成类似于宏操作的自动 ...