设为首页 加入收藏

TOP

Botan 加密算法库的简单示例
2014-11-24 11:30:38 来源: 作者: 【 】 浏览:0
Tags:Botan 加密 算法 简单 示例

Botan 是一个 C++ 的加密算法库,支持 AES, DES, SHA-1, RSA, DSA, Diffie-Hellman 等多种算法,支持 X.509 认证以及CRLs 和 PKCS #10


botan-demo.c


#include
#include
#include
using namespace Botan;


#include
#include


int main(int argc, char* argv[])
{
if(argc != 5)
{
std::cout << "Usage: " << argv[0] << " "
<< " " << std::endl;
return 1;
}


try
{
const std::string arg_passphrase = argv[1];
const std::string arg_ca_cert = argv[2];
const std::string arg_ca_key = argv[3];
const std::string arg_req_file = argv[4];


AutoSeeded_RNG rng;


X509_Certificate ca_cert(arg_ca_cert);


std::auto_ptr privkey(
PKCS8::load_key(arg_ca_key, rng, arg_passphrase)
);


X509_CA ca(ca_cert, *privkey);


// got a request
PKCS10_Request req(arg_req_file);


// you would insert checks here, and perhaps modify the request
// (this example should be extended to show how)


// now sign the request
X509_Time start_time(system_time());
X509_Time end_time(system_time() + 365 * 60 * 60 * 24);


X509_Certificate new_cert = ca.sign_request(req, rng,
start_time, end_time);


// send the new cert back to the requestor
std::cout << new_cert.PEM_encode();
}
catch(std::exception& e)
{
std::cout << e.what() << std::endl;
return 1;
}
return 0;
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇struts2中页面取值的原理以及valu.. 下一篇如何真真正正的退出Android应用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)