是否有用于散列数据数组库中的任何简单的方法? [英] Are there any easy way to use libraries for hashing data arrays?
问题描述
我正在考虑使用 CRC-32 或的 SHA-1 ,既可能在C程序中我开发在Linux(Ubuntu的)。
I am thinking about using CRC-32 or SHA-1, possibly both in a C program I develop on Linux (Ubuntu).
有没有使用库或者没有简单的方法?剪切和粘贴一个CRC-32的算法到我的程序的源$ C $ C说起来简单,但做了SHA-1同样的感觉略有不稳。是否有使用图书馆,preferably在Ubuntu,但没有简单的方法不一定?
Are there any easy way to use libraries for either? Cutting and pasting a CRC-32 algorithm into the source code of my program seems simple enough, but doing the same for SHA-1 feels slightly shaky. Are there any easy way to use libraries, preferably in Ubuntu but not necessarily?
我使用C,但是如果我不得不C ++就OK。
I am using C, but C++ would be OK if I had to.
推荐答案
OpenSSL的接口是pretty简单:
The OpenSSL interface is pretty simple:
#include <openssl/sha.h>
unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md);
D
是一个指针输入被散列,长度 N
。 MD
是一个指向 SHA_DIGEST_LENGTH
字节,其中的SHA1哈希值将被保存。
d
is a pointer to the input to be hashed, with length n
. md
is a pointer to SHA_DIGEST_LENGTH
bytes where the SHA1 hash will be stored.
这篇关于是否有用于散列数据数组库中的任何简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!