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 密钥容器.问题: ...
随机推荐
- getElementById,getElementsByName,getElementsByTagName的区别
1.getElementById 作用:一般页面里ID是唯一的,用于准备定为一个元素 语法: document.getElementById(id) 参数:id :必选项为字符串(String) 返回 ...
- 给button按钮加回车事件
<button class="login-btn" id="login">立即登录</button> $("body" ...
- github:如何获取项目源代码
github是流行的源码管理平台.这上面有很多开源的项目.作为普通的用户,如何获取这些开源项目的源码呢? 1.首先需要注册一个github账号. 2.安装windows下的git工具:下载地址: ht ...
- zend studio 的使用
1.将php项目导入到zend studio 中的方式为:http://my.oschina.net/maomi/blog/86077: 2.zend studio中将php项目导出的方式为:如果你会 ...
- Sqlserver 函数
SQL2008 表达式:是常量.变量.列或函数等与运算符的任意组合. 1. 字符串函数 函数 名称 参数 示例 说明 ascii(字符串表达式) select ascii('abc') 返回 97 返 ...
- 解决 502、504 Gateway Time-out(nginx)
一.504 Gateway Time-out问题常见于使用nginx作为web server的服务器的网站 我遇到这个问题是在升级discuz论坛的时候遇到的 一般看来, 这种情况可能是由于nginx ...
- 代理模式(Proxy Pattern)
一.引言 在软件开发过程中,有些对象有时候会由于网络或其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让代 ...
- SPOJ-SUBST1 New Distinct Substrings(后缀数组)
题目大意:判断总共有多少种不同的子串. 题目分析:不同的子串数目为 Σ(后缀SA[i]的长度-height[i]). 代码如下: # include<iostream> # include ...
- 前端学习 第七弹: Javascript实现图片的延迟加载
前端学习 第七弹: Javascript实现图片的延迟加载 为了实现图片进入视野范围才开始加载首先: <img src="" x-src="/acsascas ...
- LEETCODE —— Linked List Cycle [Floyd's cycle-finding algorithm]
Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it ...