openssl之EVP系列之9---EVP_Digest系列函数的一个样例
openssl之EVP系列之9---EVP_Digest系列函数的一个样例
---依据openssl doc/crypto/EVP_DigestInit.pod翻译
(作者:DragonKing, Mail: wzhah@263.net ,公布于:http://openssl.126.com 之openssl专业论坛,版本号:openssl-0.9.7)
本样例是openssl帮助文档提供的。该样例依据命令行输入的信息摘要算法名字对"Test Message/n"和"Hello World/n"字符串进行信息摘要操作。
#include <stdio.h>
#include <openssl/evp.h>
main(int argc, char *argv[])
{
EVP_MD_CTX mdctx;
const EVP_MD *md;
char mess1[] = "Test Message/n";
char mess2[] = "Hello World/n";
unsigned char md_value[EVP_MAX_MD_SIZE];
int md_len, i;
//使EVP_Digest系列函数支持全部有效的信息摘要算法
OpenSSL_add_all_digests();
if(!argv[1]) {
printf("Usage: mdtest digestname/n");
exit(1);
}
//依据输入的信息摘要函数的名字得到对应的EVP_MD算法结构
md = EVP_get_digestbyname(argv[1]);
if(!md) {
printf("Unknown message digest %s/n", argv[1]);
exit(1);
}
//初始化信息摘要结构mdctx。这在调用EVP_DigestInit_ex函数的时候是必须的。
EVP_MD_CTX_init(&mdctx);
//使用md的算法结构设置mdctx结构,impl为NULL,即使用缺省实现的算法(openssl本身提供的信息摘要算法)
EVP_DigestInit_ex(&mdctx, md, NULL);
//開始真正进行信息摘要运算,能够多次调用该函数。处理很多其它的数据,这里仅仅调用了两次
EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
//完毕信息摘要计算过程,将完毕的摘要信息存储在md_value里面,长度信息存储在md_len里面
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
//使用该函数释放mdctx占用的资源,假设使用_ex系列函数,这是必须调用的。
EVP_MD_CTX_cleanup(&mdctx);
printf("Digest is: ");
for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
printf("/n");
}
openssl之EVP系列之9---EVP_Digest系列函数的一个样例的更多相关文章
- OpenSSL EVP_Digest系列函数的一个样例
#include <stdio.h> #include <openssl/evp.h> main(int argc, char *argv[]) ...
- openssl之EVP系列之1---算法封装
openssl之EVP系列之1---算法封装 ---依据openssl doc/crypto/EVP.pod翻译和自己的理解写成 (作者:DragonKing, Mail: wzhah ...
- openssl之EVP系列之8---EVP_Digest系列函数具体解释
openssl之EVP系列之8---EVP_Digest系列函数具体解释 ---依据openssl doc/crypto/EVP_DigestInit.pod翻译和自己的理解写成 (作 ...
- openssl之EVP系列之10---EVP_Sign系列函数介绍
openssl之EVP系列之10---EVP_Sign系列函数介绍 ---依据openssl doc/crypto/EVP_SignInit.pod翻译 (作者:DragonKing, ...
- openssl之EVP系列之13---EVP_Open系列函数介绍
openssl之EVP系列之13---EVP_Open系列函数介绍 ---依据openssl doc/crypto/EVP_OpenInit.pod翻译和自己的理解写成 (作者:Dra ...
- openssl之EVP系列之7---信息摘要算法结构概述
openssl之EVP系列之7---信息摘要算法结构概述 ---依据openssl doc/crypto/EVP_DigestInit.pod翻译和自己的理解写成 (作者:Dragon ...
- openssl之EVP系列之12---EVP_Seal系列函数介绍
openssl之EVP系列之12---EVP_Seal系列函数介绍 ---依据openssl doc/crypto/EVP_SealInit.pod翻译和自己的理解写成 (作者:Dra ...
- openssl之EVP系列之11---EVP_Verify系列函数介绍
openssl之EVP系列之11---EVP_Verify系列函数介绍 ---依据openssl doc/crypto/EVP_VerifyInit.pod翻译和自己的理解写成 (作者 ...
- openssl之EVP系列之6---EVP_Encrypt系列函数编程架构及样例
openssl之EVP系列之6---EVP_Encrypt系列函数编程架构及样例 ---依据openssl doc/crypto/EVP_EncryptInit.pod和doc/ssleay. ...
随机推荐
- GO语言基础之interface
接口interface 1. 接口是一个或多个方法签名的集合 2. 只要某个类型拥有该接口的所有方法签名,即算实现该接口,无需显示声明实现了哪个接口,这称为 Structural typing 3. ...
- UICamera(NGUI Event system)原理
看了UICamera的源码就显而易见了: UICamera « on: November 21, 2013, 12:21:48 AM » Overview UICamera is a somewh ...
- 如何监控执行的SQL语句?
环境: SQL Server 2012. 打开SQL Server Profiler. 在菜单中选择New Trace, 连接上SQL Server. 在弹出的窗口中选择Event selection ...
- leetcode笔记:Sqrt(x)
一. 题目描写叙述 Implement int sqrt(int x). Compute and return the square root of x. 二. 题目分析 该题要求实现求根公式,该题还 ...
- springboot项目打包提示Unable to find a single main class from the following candidates错误
提示Unable to find a single main class from the following candidates错误的原因是会从所有代码里面扫描包括main方法的类,找到多个类就报 ...
- ubuntu server vsftpd 虚拟用户及目录
ubuntu server vsftpd 虚拟用户及目录 一:需求场景: 在ubuntu server上开设一个虚拟网站,在网站目录建立一个ftp目录,允许用户通过ftp上传网站文件到网站目录: 同时 ...
- cordova 常用插件
一,插件相关常用命令 1,查看所有已经安装的插件 1 cordova plugin ls 2,安装插件(以camera插件为例) 1 cordova plugin add cordova-plug ...
- nginx 备忘
下载 start nginxlocalhost:80
- SQL Server表描述 及 字段描述的增、删、改、查询
SQL Server表描述 及 字段描述的增.删.改.查询 --测试: --创建表及描述信息 ),isname )) --为表添加描述信息 EXECUTE sp_addextendedproperty ...
- Android 如何将Canvas上绘制的内容保存成本地图片(转)
效果如下图所示 保存在sd卡上的文件为 手机上显示效果为: 1>>在Manifest文件中增加相应权限 <!-- 在SDCard中创建与删除文件权限 --> <uses- ...