eccrypto.h提供了基于椭圆曲线加密操作的一系列模板类,将这些类设计成模板主要的原因是有两种类型椭圆曲线。因此,类EC2N(ec2n.h)代表的是基于GF(2n)的椭圆曲线算法;而类ECP(ecp.h)代表的是基于GF(p)的椭圆曲线算法。
椭圆曲线的参数保存在模板类ECParameters中,参数能够以多种方式初始化;但是其中一个更实用的用法是使用函数LoadRecommendedParameters(),它提供了建议参数之一,定义在oids.h中。
下面看几个实例代码:
1)生成一个EC2N密钥对,并保存之:
// ECPrivateKey is used directly only because the private key
// won't actually be used to perform any cryptographic operation.
AutoSeededRandomPool rng;
ECPrivateKey privkey(rng, ASN1::sect233k1);
Base64Encoder privkeysink(new FileSink("c://privkey.txt"));
privkey.DEREncode(privkeysink);
privkeysink.MessageEnd(); // Need to flush Base64Encoder's buffer
// Suppose we want to store the public key separately,
// possibly because we will be sending the public key to a third party.
ECPublicKey pubkey(privkey);
Base64Encoder pubkeysink(new FileSink("c://pubkey.txt"));
pubkey.DEREncode(pubkeysink);
pubkeysink.MessageEnd(); // Need to flush Base64Encoder's buffer
2)加载公钥,并加密一个文件:
string sContents;
FileSource("c://tobesigned.dat", true,
new StringSink(sContents));
ECEncryptor pubkey(
FileSource("c://pubkey.txt", true,
new Base64Decoder)));
// Cannot use std::string for buffer;
// its internal storage might not be contiguous
SecByteBlock sbbCipherText(pubkey.CipherTextLength(sContents.size()));
// ECIES encryption is nice because it handles the entire encryption
// process internally, regardless of the length of input data.
// We don't have to generate a symmetric session key and encrypt
// with it separately.
AutoSeededRandomPool rng;
pubkey.Encrypt(
rng,
(byte const*) sContents.data(),
sContents.size(),
sbbCipherText.Begin());
FileSink("c://encrypted.dat").Put(sbbCipherText.Begin(), sbbCipherText.Size());
分享到:
相关推荐
asce1885-blogasce1885的博客
mfc工程,一个可以编辑,选择能实现众多功能的list控件示范工程,
PHASE II OF THE ASCE BENCHMARK STUDY ON SHM
此为ASCE的第三代基准模型代码,可供土木工程领域学者使用。
ASCE7-10-建筑物和其他结构最小设计荷载-中文版.pdf
ASCE全文数据库培训iGroup公司.ppt
ASCE是土木工程学会的重要期刊。国外期刊投稿主要是latex,该期刊有Latex的投稿模板。
土木工程几个著名期刊ASCE和Science direct中输出格式
希望大家能用得着这个东西!检索时很有用啊
ASCE_7-10美国建筑荷载规范(中文版);.pdf
eclipse 配置AmaterasUML时需要的3个jar 包,以及配置文档 http://blog.csdn.net/asce1885/article/details/40744163
ASCE-7-2005-美国荷载规范-(中文版)
ANSI ASCE CI 71-21 Identifying, Quantifying, and Proving Loss of Productivity.pdf
结构安全和结构动力学有许多领域,通常需要计算随机变量函数的前几个统计矩。 通常的近似是泰勒展开法。 这种方法需要计算导数。 为了避免导数的计算,已经提出了概率矩的点估计。 然而,准确度非常低,并且有时,...
针对美国IASC-ASCE的结构健康监测科研组提出的基准结构进行结构自振频率识别研究.神经网络训练时使用的数据为有限元程序计算所得出,将有损伤结构在环境激励下某点的加速度响应,通过快速傅立叶变换得到的离散频率响应...
国ASCE 7-10 《建筑物和其他结构最小设计荷载》 (ASCE 7-10 “Minimum Design Loads for Buildings and Other Structures”)主要内容翻译与介绍 目录 0 规范内容简介1 1 总则7 1.1 适用范围7 1.2 定义和解释7 1.3 ...
该demo实现qt控件拖拽效果,代码是基于Qt5版本,部分类容是加强拖拽效果的,如阴影图片,也可以自己删去
这是一个有效的应用程序,为结构工程师提供了一个用户友好的环境来分析不同的结构,桁架,结构,剪力墙,基础,载体墙,地板加热系统,木结构,陶瓷,石工,和铝。支持IBC、ASCE 7、NBC、ACI 318-14、AISC360-16 ASD...
asce-common 可以重用并轻松集成到任何项目中的android通用代码
应用该方法对由国际结构控制协会与美国土木工程学会(IASC-ASCE)提出的健康监测Benchmark结构进行了分析。结果表明,两阶段损伤诊断方法能够;隹确地定出可能损伤单元的位置与损伤程度,识别结果与真实的损伤接近,...