STTNet 0.7.0
Loading...
Searching...
No Matches
stt::data::CryptoUtil Class Reference

负责加密,解密和哈希 More...

#include <sttnet.h>

Static Public Member Functions

static bool encryptSymmetric (const unsigned char *before, const size_t &length, const unsigned char *passwd, const unsigned char *iv, unsigned char *after)
 AES-256-CBC模式对称加密函数
 
static bool decryptSymmetric (const unsigned char *before, const size_t &length, const unsigned char *passwd, const unsigned char *iv, unsigned char *after)
 AES-256-CBC模式对称解密函数
 
static std::string & sha1 (const std::string &ori_str, std::string &result)
 计算输入字符串的 SHA-1 哈希值(原始二进制形式)。
 
static std::string & sha11 (const std::string &ori_str, std::string &result)
 计算输入字符串的 SHA-1 哈希值,并以十六进制字符串形式返回。
 

Detailed Description

AES-256-CBC and SHA-1 compatibility utilities.

New 0.7.0 overloads:
static bool encryptSymmetric(..., unsigned char *after, size_t &outputLength);
static bool decryptSymmetric(..., unsigned char *after, size_t &outputLength);
  • New code should use the outputLength overloads rather than guessing binary lengths.
  • AES-CBC does not authenticate ciphertext; add authentication or use an AEAD design.
  • SHA-1 is retained only for existing protocol compatibility, not passwords, signatures, or new security designs.

The five-argument overloads remain for compatibility. See include/sttnet.h for exact signatures.

Member Function Documentation

◆ decryptSymmetric()

static bool stt::data::CryptoUtil::decryptSymmetric ( const unsigned char * before,
const size_t & length,
const unsigned char * passwd,
const unsigned char * iv,
unsigned char * after )
static

AES-256-CBC模式对称解密函数

Parameters
before密文的数据容器
length密文的数据长度
passwd密钥
iviv向量
after解密后的数据容器
Returns
true:解密成功 false:解密失败
Note
AES-256-CBC模式下 密钥为32字节 iv向量为16字节

◆ encryptSymmetric()

static bool stt::data::CryptoUtil::encryptSymmetric ( const unsigned char * before,
const size_t & length,
const unsigned char * passwd,
const unsigned char * iv,
unsigned char * after )
static

AES-256-CBC模式对称加密函数

Parameters
before加密前的数据容器
length数据前的数据长度
passwd密钥
iviv向量
after密文的数据容器
Returns
true:加密成功 false:加密失败
Note
AES-256-CBC模式下 密钥为32字节 iv向量为16字节

◆ sha1()

static std::string & stt::data::CryptoUtil::sha1 ( const std::string & ori_str,
std::string & result )
static

计算输入字符串的 SHA-1 哈希值(原始二进制形式)。

使用 OpenSSL 的 SHA1 函数对输入字符串进行哈希处理,结果以 20 字节的原始二进制形式存储在 result 中。 注意:result 可能包含不可打印字符,不适合直接输出或写入文本。

Parameters
ori_str输入的原始字符串。
result用于存放输出的 SHA-1 哈希值(二进制形式),长度为 20 字节。
Returns
返回 result 的引用。
Note
该函数适用于后续加密、签名等处理(例如用于 HMAC 的输入)。

◆ sha11()

static std::string & stt::data::CryptoUtil::sha11 ( const std::string & ori_str,
std::string & result )
static

计算输入字符串的 SHA-1 哈希值,并以十六进制字符串形式返回。

使用 OpenSSL 的 SHA1 函数对输入字符串进行哈希处理,结果以 40 个字符的十六进制格式表示存储在 result 中。 每个字节转换为两个十六进制字符,可直接用于打印、日志记录、存储等可读场景。

Parameters
ori_str输入的原始字符串。
result用于存放输出的 SHA-1 哈希值(40 字节的十六进制字符串)。
Returns
返回 result 的引用。
Note
适用于哈希显示、唯一标识、日志校验等场景。与 sha1 的主要区别是输出格式。

The documentation for this class was generated from the following file: