2025-09-20 16:41:08 +08:00
|
|
|
|
#ifndef _Crypto_H_
|
2025-08-20 19:00:22 +08:00
|
|
|
|
#define _Crypto_H_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
#include <string>
|
2025-09-20 16:41:08 +08:00
|
|
|
|
#include <gmssl/sm4.h>
|
|
|
|
|
|
#include <gmssl/hex.h>
|
|
|
|
|
|
#include <gmssl/sm2.h>
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Crypto
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
static string md5(string src);
|
|
|
|
|
|
|
2025-09-20 16:41:08 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief SM4-ECB 加密示例
|
|
|
|
|
|
* @param key 16字节密钥
|
|
|
|
|
|
* @param plaintext 明文数据
|
|
|
|
|
|
* @return 密文字节向量
|
|
|
|
|
|
*/
|
|
|
|
|
|
static std::vector<uint8_t> sm4EcbEncrypt(const std::vector<uint8_t>& key, const std::vector<uint8_t>& plaintext);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief SM4-ECB 解密示例
|
|
|
|
|
|
* @param key 16字节密钥
|
|
|
|
|
|
* @param ciphertext 密文数据
|
|
|
|
|
|
* @return 明文字节向量
|
|
|
|
|
|
*/
|
|
|
|
|
|
static std::vector<uint8_t> sm4EcbDecrypt(const std::vector<uint8_t>& key, const std::vector<uint8_t>& ciphertext);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ! _Crypto_H_
|