Linux C 下使用openssl 进行SHA1加密
2007-05-11 18:03
489 查看
How to replace hash functions from openssl with gcrypt. I wondered how to do it, and hacked around. git source uses ssl, and I wanted that to change.
/*
Code snippet to calculate SHA1sum using openssl libs.
Copyright 2005 Junichi Uekawa, given to public domain.
$ gcc openssltest.c -lssl
$ ./a.out < ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554
$ sha1sum ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554 ./a.out
*/
#include <stdio.h>
#include <openssl/sha.h>
main ()
{
SHA_CTX s;
int i, size;
char c[512];
unsigned char hash[20];
SHA1_Init(&s);
while ((size=read (0, c, 512)) > 0)
SHA1_Update(&s, c, size);
SHA1_Final(hash, &s);
for (i=0; i < 20; i++)
printf ("%.2x", (int)hash[i]);
printf ("\n");
}
/*
Code snippet to calculate SHA1sum using openssl libs.
Copyright 2005 Junichi Uekawa, given to public domain.
$ gcc openssltest.c -lssl
$ ./a.out < ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554
$ sha1sum ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554 ./a.out
*/
#include <stdio.h>
#include <openssl/sha.h>
main ()
{
SHA_CTX s;
int i, size;
char c[512];
unsigned char hash[20];
SHA1_Init(&s);
while ((size=read (0, c, 512)) > 0)
SHA1_Update(&s, c, size);
SHA1_Final(hash, &s);
for (i=0; i < 20; i++)
printf ("%.2x", (int)hash[i]);
printf ("\n");
}
相关文章推荐
- 如何使用java进行sha1加密
- 在Linux环境下使用OpenSSL对消息和文件进行加密
- C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)
- Android 使用OpenSSL进行3DES加密 c与java互通
- 使用C语言,对OpenSSL命令行加密的文件进行解密
- 使用openssl进行ssl/tls加密传输会话测试
- 使用证书对数据进行签名、验签、加密、解密以及openssl的常用方法
- 使用openssl 生成AES加密并且对加密结果进行base64加密
- 在iOS中使用OpenSSL的Public Key 进行加密
- 使用openssl进行RSA加密解密
- C# 中使用 OpenSSL 的公钥/私钥进行加密和解密
- C/C++使用openssl进行摘要和加密解密(md5, sha256, des, rsa)
- 使用openssl库进行AES算法的加密
- 使用openssl命令进行加密解密及散列运算的命令行
- Android在NDK层使用OpenSSL进行RSA加密
- 使用Python的OpenSSL库来进行RSA加密
- 使用 OpenSSL 对文件进行加密和解密
- Java使用commons codec进行Md5,sha1,base64加密
- PHP 使用openssl 进行加密 解密
- 使用Python的OpenSSL库来进行RSA加密