VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::Security类 参考final

Thread-safe AES-128-CBC encryption/decryption utility with custom callback support. 更多...

#include <security.h>

vlink::Security 的协作图:

Public 类型

using Callback = std::function<bool(const Bytes& in, Bytes& out)>
 Callback type for custom encryption or decryption.

Public 成员函数

 Security ()
 Constructs a Security object with the default AES key and IV.
 ~Security ()
 Destroys the Security object and frees the EVP context.
void set_key (const std::string &key)
 Sets the AES encryption key.
void set_callbacks (Callback &&encrypt_callback, Callback &&decrypt_callback)
 Installs custom encrypt and decrypt callbacks, bypassing the built-in AES.
bool encrypt (const Bytes &in, Bytes &out)
 Encrypts in and writes the ciphertext into out.
bool decrypt (const Bytes &in, Bytes &out)
 Decrypts in and writes the plaintext into out.

详细描述

Thread-safe AES-128-CBC encryption/decryption utility with custom callback support.

Each Security instance holds its own EVP context and key material. Copy and assignment are disabled; instances are intended to be owned by a single transport endpoint.

成员类型定义说明

◆ Callback

using vlink::Security::Callback = std::function<bool(const Bytes& in, Bytes& out)>

Callback type for custom encryption or decryption.

Called with the input Bytes; the implementation must write the result into out and return true on success. When a custom callback is installed via set_callbacks(), the built-in AES implementation is bypassed.

构造及析构函数说明

◆ Security()

vlink::Security::Security ( )

Constructs a Security object with the default AES key and IV.

Initialises an OpenSSL EVP context with AES-128-CBC and PKCS7 padding when VLINK_ENABLE_SECURITY is defined. Otherwise logs a warning.

这是这个函数的调用关系图:

◆ ~Security()

vlink::Security::~Security ( )

Destroys the Security object and frees the EVP context.

成员函数说明

◆ decrypt()

bool vlink::Security::decrypt ( const Bytes & in,
Bytes & out )

Decrypts in and writes the plaintext into out.

Uses the custom decrypt callback if installed, otherwise uses AES-128-CBC. If in is empty, out is unchanged and true is returned immediately.

参数
inCiphertext bytes.
outOutput buffer for plaintext. Overwritten on success.
返回
true on success; false if decryption fails or the feature is disabled.
函数调用图:

◆ encrypt()

bool vlink::Security::encrypt ( const Bytes & in,
Bytes & out )

Encrypts in and writes the ciphertext into out.

Uses the custom encrypt callback if installed, otherwise uses AES-128-CBC. If in is empty, out is unchanged and true is returned immediately.

参数
inPlaintext bytes.
outOutput buffer for ciphertext. Overwritten on success.
返回
true on success; false if encryption fails or the feature is disabled.

◆ set_callbacks()

void vlink::Security::set_callbacks ( Callback && encrypt_callback,
Callback && decrypt_callback )

Installs custom encrypt and decrypt callbacks, bypassing the built-in AES.

When both callbacks are set, encrypt() delegates to encrypt_callback and decrypt() delegates to decrypt_callback. Set to nullptr to fall back to the built-in AES implementation.

参数
encrypt_callbackCustom encryption function.
decrypt_callbackCustom decryption function.

◆ set_key()

void vlink::Security::set_key ( const std::string & key)

Sets the AES encryption key.

The key string is stored as Bytes. If key is empty, the default built-in key "vlink" is restored. The key length is not validated here; OpenSSL will use the first 16 bytes for AES-128.

参数
keyKey string. Pass an empty string to restore the default.

该类的文档由以下文件生成: