OpenSSL 用SM3算法进行hash
生活随笔
收集整理的這篇文章主要介紹了
OpenSSL 用SM3算法进行hash
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
OpenSSL 用SM3算法進(jìn)行hash
如果需要使用 SM3 Hash 操作,則需要使用1.1.1以上版本的OpenSSL。
主要是用到了 Openssl EVP (high-level cryptographic functions),它提供了豐富的密碼學(xué)中的函數(shù)。
具體實(shí)現(xiàn):
#include <openssl/evp.h> #include <openssl/aes.h>bool openssl_sm3_hash(const vector<string>& input, unsigned char* buffer, unsigned int* buf_len) {if (input.empty())return false;memset(buffer, 0, *buf_len);EVP_MD_CTX* ctx = EVP_MD_CTX_new();// 設(shè)置使用SM3if (!EVP_DigestInit_ex(ctx, EVP_sm3(), NULL)) {cout << "Failed to init" << endl;return false;}for (const auto& i: input) {if (!EVP_DigestUpdate(ctx, i.c_str(), i.size())) {cout << "Failed to update" << endl;return false;}}if (!EVP_DigestFinal_ex(ctx, buffer, buf_len)) {cout << "Failed to final" << endl;return false;}EVP_MD_CTX_free(ctx);return true; }總結(jié)
以上是生活随笔為你收集整理的OpenSSL 用SM3算法进行hash的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Debian10: 安装iF.SVNAd
- 下一篇: icem密度盒怎么设置_ICEM-自动体