STTNet
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Static Public Member Functions | List of all members
stt::data::CryptoUtil Class Reference

Responsible for encryption, decryption, and hashing. More...

#include <sttnet_English.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)
 Symmetric encryption function in AES-256-CBC mode. More...
 
static bool decryptSymmetric (const unsigned char *before, const size_t &length, const unsigned char *passwd, const unsigned char *iv, unsigned char *after)
 Symmetric decryption function in AES-256-CBC mode. More...
 
static std::string & sha1 (const std::string &ori_str, std::string &result)
 Calculate the SHA-1 hash value (raw binary form) of the input string. More...
 
static std::string & sha11 (const std::string &ori_str, std::string &result)
 Calculate the SHA-1 hash value of the input string and return it as a hexadecimal string. More...
 

Detailed Description

Responsible for encryption, decryption, and hashing.

Member Function Documentation

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

Symmetric decryption function in AES-256-CBC mode.

Parameters
beforeData container for ciphertext
lengthLength of the ciphertext
passwdDecryption key
ivIV vector
afterData container for decrypted data
Returns
true: Decryption successful, false: Decryption failed
Note
In AES-256-CBC mode, the key is 32 bytes and the iv vector is 16 bytes
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

Symmetric encryption function in AES-256-CBC mode.

Parameters
beforeData container before encryption
lengthLength of the data
passwdEncryption key
ivIV vector
afterData container for ciphertext
Returns
true: Encryption successful, false: Encryption failed
Note
In AES-256-CBC mode, the key is 32 bytes and the iv vector is 16 bytes
static std::string& stt::data::CryptoUtil::sha1 ( const std::string &  ori_str,
std::string &  result 
)
static

Calculate the SHA-1 hash value (raw binary form) of the input string.

Uses OpenSSL's SHA1 function to hash the input string, and the result is stored in result in 20-byte raw binary form. Note: result may contain non-printable characters and is not suitable for direct output or writing to text.

Parameters
ori_strInput original string.
resultUsed to store the output SHA-1 hash value (binary form), 20 bytes in length.
Returns
Reference to result.
Note
This function is suitable for subsequent encryption, signature, etc. (e.g., for HMAC input).
static std::string& stt::data::CryptoUtil::sha11 ( const std::string &  ori_str,
std::string &  result 
)
static

Calculate the SHA-1 hash value of the input string and return it as a hexadecimal string.

Uses OpenSSL's SHA1 function to hash the input string, and the result is stored in result in a 40-character hexadecimal format. Each byte is converted to two hexadecimal characters, which can be directly used for readable scenarios such as printing, logging, and storage.

Parameters
ori_strInput original string.
resultUsed to store the output SHA-1 hash value (40-byte hexadecimal string).
Returns
Reference to result.
Note
Suitable for hash display, unique identification, log verification, etc. The main difference from sha1 is the output format.

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