Generate SHA hash in C++ using OpenSSL library
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I generate SHA1 or SHA2 hashes using the OpenSSL libarary? I searched google and could not find any function or example code. 回答1: From the command line, it's simply: printf "compute sha1" | openssl sha1 You can invoke the library like this: #include <stdio.h> #include <string.h> #include <openssl/sha.h> int main() { unsigned char ibuf[] = "compute sha1"; unsigned char obuf[20]; SHA1(ibuf, strlen(ibuf), obuf); int i; for (i = 0; i < 20; i++) { printf("%02x ", obuf[i]); } printf("\n"); return 0; } 回答2: OpenSSL has a horrible