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. RBM阅读笔记

    RBM包含两个层,可见层(visble layer)和隐藏层(hidden layer).神经元之间的连接具有以下特点:层内无连接,层间全连接.RBM可以看做是一个二分图(神经元当做顶点,神经元之间的 ...

  2. 2. Transcribing DNA into RNA

    Problem An RNA string is a string formed from the alphabet containing 'A', 'C', 'G', and 'U'. Given ...

  3. 将list中的数据通过某一个字段来分类存储的实例

    现有学生表 public class Student { /** * 班级id */ private String classId; /** * 学生name */ private String na ...

  4. applicationCache对象

    applicationCache对象代表了本地缓存,可以在js中进行一些操作.可以用它来通知用户本地缓存中已经被更新,也允许用户手工更新本地缓存.applicationCache.addEventLi ...

  5. python杂七杂八小问题

    1.win7系统下,安装完GTK+后,从命令行界面无法启动ipython,提示“failed to create process”.运行easy_install也遇到了这个问题. 原因是安装GTK+时 ...

  6. php 以IP的形式获取访问者的地理位置

    <?php header('Content-Type:text/html;charset=utf-8'); function getIPLoc_sina($queryIP){ $url = 'h ...

  7. Javascript 中的神器——Promise

    Promise in js 回调函数真正的问题在于他剥夺了我们使用 return 和 throw 这些关键字的能力.而 Promise 很好地解决了这一切. 2015 年 6 月,ECMAScript ...

  8. (转) Awesome - Most Cited Deep Learning Papers

    转自:https://github.com/terryum/awesome-deep-learning-papers Awesome - Most Cited Deep Learning Papers ...

  9. iostat

    http://m.blog.csdn.net/article/details?id=43196731 http://blog.csdn.net/haiross/article/details/4319 ...

  10. SSL安全证书-概念解析

    一.关于证书 数字证书是一种认证机制.简单点说,它代表了一种由权威机构颁发授权的安全标志. 由来 在以前,传统网站采用HTTP协议进行数据传输,所有的数据几乎都用的明文,很容易发生隐私泄露.为了解决安 ...