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. JavaScript+HTML,简单的计算器实现

    成功进化到程序猿快一年多了, 还没写过计算器, 正好今天比较闲,随手写了个计算器,最简单的实现,核心是eval()方法,把字符串作为JS代码处理,把输入的信息拼接成字符串,点等号执行代码得到结果,出异 ...

  2. Github注册账户过程

    首先打开网站https://github.com/ 第一个是输入用户名第二个是邮箱第三个是自己的密码然后点    sign up for github 此时会有个邮箱注册的验证进入注册的邮箱点击认证. ...

  3. SpringMVC中定时器继承Task后无法对service注入问题

    最近在做一个Spring+MyBatis的一个项目,其中用到了Redis的存储,然后遇到问题是这样的: RedisTask是通过定时器来每分钟像数据库里推送的,于是就有了 public class R ...

  4. cannot simultaneously fetch multiple bags

    问题是什么时候出现的呢?    当一个实体对象中包含多于一个non-lazy获取策略时,比如@OneToMany,@ManyToMany或者@ElementCollection时,获取策略为(fetc ...

  5. radio值未出现JQ获取值问题

    $('input:radio[name="modelExtend.manageType"]:checked').val(); 选中的获取的值不是空或者null而是on

  6. 使用keepalived实现mysql主从复制的自动切换

    最近测试了一下mysql+keepalived实现主从自动切换,主从都需要安装keepalived,使用vip漂移实现主从自动切换,这里主要记录的是keepalived的文件配置. 这里mysql搭建 ...

  7. LINQ 客户端生成自增列

    var testQuery = (from item in TestInfo.GroupBy(t=>t.TestName) select new { TestCode = item.Min(g= ...

  8. PHP在yii2中封装SuperSlide 幻灯片编写自己的SuperSlideWidget的例子

    因为近期给朋友公司做个门户网站,把荒置了6.7年的PHP又重新拾起,发现PHP这些年兴旺多了,很多新的东西看的不明不白,研究了几个框架ZendFramework.thinkphp.Symfony.yi ...

  9. geohash-net实现

    基于c#语言 geohash算法基本实现源码,参见: https://github.com/sharonjl/geohash-net , 源码中具体包含如下方法: String CalculateAd ...

  10. Beta版本冲刺——day2

    No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 站立式会议 培侨走的第5天,想他~( ...