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. ...
随机推荐
- SQL基础(一):SQL语法和命令
一.语法: 1.SQL 对大小写不敏感:SELECT 与 select 是相同的. 2.某些数据库系统要求在每条 SQL 语句的末端使用分号.分号是在数据库系统中分隔每条 SQL 语句的标准方法,这样 ...
- python 分词计算文档TF-IDF值并排序
文章来自于我的个人博客:python 分词计算文档TF-IDF值并排序 该程序实现的功能是:首先读取一些文档,然后通过jieba来分词,将分词存入文件,然后通过sklearn计算每一个分词文档中的tf ...
- 【LeetCode】Path Sum II 二叉树递归
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- SQL Server-已更新或删除的行值要么不能使该行成为唯一行,要么改变了多个行
在更新没有设置主键的表的时候出现下图中的问题: 问题原因: 这种问题大多是由于没有主键(PK)导致同一张表中存在若干条相同的数据 DBMS存储时,只为其存储一条数据,因为DBMS底层做了优化,以减少数 ...
- 笔记本wifi热点设置好后,手机连上但不能上网问题
这个问题我遇到过,我的原因是因为电脑上装有安全防护软件360的原因 解决方法是:打开360-->找到功能大全中的流量防火墙-->打开局域网防护-->关闭局域网隐身功能,立刻解决了这个 ...
- System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- springboot项目打包提示Unable to find a single main class from the following candidates错误
提示Unable to find a single main class from the following candidates错误的原因是会从所有代码里面扫描包括main方法的类,找到多个类就报 ...
- 下载 jdk
1.下载JDK: 首先我们需要下载java开发工具包JDK,下载地址如下: http://www.oracle.com/technetwork/java/javase/downloads/index. ...
- SAP SQ01怎样从开发机传输到生产机
确认你的Query是本地的还是全局的(跨Client).假设是后者,会自己主动生成传输请求,用标准传输方式就可以. 假设是本地的Query,有两种方式: 方式1:复制成全局的,让后生成传输请求 方式2 ...
- Spring <context:annotation-config/> 说明
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册AutowiredAn ...