Skip to content

Callbacks - CryptoCb

Functions

Name
int wc_BufferKeyDecrypt(struct EncryptedInfo * info, byte * der, word32 derSz, const byte * password, int passwordSz, int hashType)
This function decrypts an encrypted key buffer using the provided password. It supports various encryption algorithms including DES, 3DES, and AES. The encryption information is provided in the EncryptedInfo structure.
int wc_BufferKeyEncrypt(struct EncryptedInfo * info, byte * der, word32 derSz, const byte * password, int passwordSz, int hashType)
This function encrypts a key buffer using the provided password. It supports various encryption algorithms including DES, 3DES, and AES. The encryption information is provided in the EncryptedInfo structure.

Functions Documentation

function wc_BufferKeyDecrypt

int wc_BufferKeyDecrypt(
    struct EncryptedInfo * info,
    byte * der,
    word32 derSz,
    const byte * password,
    int passwordSz,
    int hashType
)

This function decrypts an encrypted key buffer using the provided password. It supports various encryption algorithms including DES, 3DES, and AES. The encryption information is provided in the EncryptedInfo structure.

Parameters:

  • info pointer to EncryptedInfo structure containing encryption algorithm and parameters
  • der pointer to the encrypted key buffer
  • derSz size of the encrypted key buffer
  • password pointer to the password buffer
  • passwordSz size of the password
  • hashType hash algorithm to use for key derivation

See: wc_BufferKeyEncrypt

Return:

  • Length of decrypted key on success
  • Negative value on error

Example

EncryptedInfo info;
byte encryptedKey[]; // encrypted key data
byte password[] = "mypassword";

int ret = wc_BufferKeyDecrypt(&info, encryptedKey,
                              sizeof(encryptedKey), password,
                              sizeof(password)-1, WC_SHA256);
if (ret < 0) {
    // decryption error
}

function wc_BufferKeyEncrypt

int wc_BufferKeyEncrypt(
    struct EncryptedInfo * info,
    byte * der,
    word32 derSz,
    const byte * password,
    int passwordSz,
    int hashType
)

This function encrypts a key buffer using the provided password. It supports various encryption algorithms including DES, 3DES, and AES. The encryption information is provided in the EncryptedInfo structure.

Parameters:

  • info pointer to EncryptedInfo structure containing encryption algorithm and parameters
  • der pointer to the key buffer to encrypt
  • derSz size of the key buffer
  • password pointer to the password buffer
  • passwordSz size of the password
  • hashType hash algorithm to use for key derivation

See: wc_BufferKeyDecrypt

Return:

  • Length of encrypted key on success
  • Negative value on error

Example

EncryptedInfo info;
byte key[]; // key data to encrypt
byte password[] = "mypassword";

info.algo = AES256CBCb;
int ret = wc_BufferKeyEncrypt(&info, key, sizeof(key), password,
                              sizeof(password)-1, WC_SHA256);
if (ret < 0) {
    // encryption error
}

Updated on 2025-12-31 at 01:16:03 +0000