Compartir a través de


BCryptEncapsulate function

Note

Cierta información se relaciona con un producto de versión preliminar que puede modificarse sustancialmente antes de su publicación comercial. Microsoft no ofrece ninguna garantía, expresa o implícita, con respecto a la información proporcionada aquí. La característica descrita en este tema está disponible en versiones preliminares de Windows Insider Preview.

The BCryptEncapsulate function performs the Encapsulation operation of a Key Encapsulation Mechanism (KEM). Genera una clave secreta compartida y la cifra con la clave pública proporcionada para generar un texto cifrado KEM, devolviendo tanto la clave secreta compartida como el texto cifrado KEM.

Syntax

NTSTATUS BCryptEncapsulate(
  _In_  BCRYPT_KEY_HANDLE hKey,
  _Out_writes_bytes_to_opt_(cbSecretKey ,*pcbSecretKey)
        PUCHAR            pbSecretKey,
  _In_  ULONG             cbSecretKey,
  _Out_ ULONG             *pcbSecretKey,
  _Out_writes_bytes_to_opt_(cbCipherText ,*pcbCipherText)
        PUCHAR            pbCipherText,
  _In_  ULONG             cbCipherText,
  _Out_ ULONG             *pcbCipherText,
  _In_  ULONG             dwFlags
);

Parameters

hKey[in]

Identificador de la clave que se va a usar para la operación de encapsulación. This key must contain a public (encapsulation) key, and the handle would typically be obtained by using BCryptImportKeyPair with a public key BLOB for the KEM algorithm. También es posible usar un identificador de clave privada para la operación de encapsulación, ya que los identificadores de clave privada keM representan un par de claves.

pbSecretKey[out]

Puntero a un búfer que recibe la clave secreta compartida. See remarks for more information.

cbSecretKey[in]

The size, in bytes, of the pbSecretKey buffer.

pcbSecretKey[out]

A pointer to a ULONG variable that the receives the number of bytes written to pbSecretKey buffer.

If pbSecretKey is NULL, this receives the size, in bytes, required for the shared secret key. See remarks for more information.

pbCipherText[out]

Puntero a un búfer que recibe el texto cifrado KEM. See remarks for more information.

cbCipherText[in]

The size, in bytes, of the pbCipherText buffer.

pcbCipherText[out]

A pointer to a ULONG variable that the receives the number of bytes written to pbCipherText buffer.

If pbCipherText is NULL, this receives the size, in bytes, required for the KEM ciphertext. See remarks for more information.

dwFlags[in]

Reservado, debe ser cero.

Return value

Devuelve un código de estado que indica el éxito o error de la función.

Entre los códigos de retorno posibles se incluyen, entre otros, los siguientes.

Return Code Description
STATUS_SUCCESS La función se realizó correctamente.
STATUS_INVALID_PARAMETER One or more required parameters (hKey, pcbSecretKey, pcbCipherText) is NULL, or one of the parameters has an invalid value.
STATUS_INVALID_BUFFER_SIZE A buffer size (cbSecretKey, cbCipherText) does not match the expected size for the KEM parameters associated with the encapsulation key. *pcbSecretKey receives the number of bytes required for pbSecretKey, pcbCipherText receives the number of bytes required for pbCipherText.
STATUS_BUFFER_TOO_SMALL An output buffer size (cbSecretKey, cbCipherText) is too small for the result encapsulation operation for the KEM parameters associated with the encapsulation key. pcbSecretKey receives the number of bytes required for pbSecretKey, pcbCipherText receives the number of bytes required for pbCipherText.

Remarks

To query the required sizes of the pbSecretKey and pbCipherText buffers, callers may call BCryptEncapsulate with NULLpbSecretKey and pbCipherText. The required sizes will be returned in pcbSecretKey and pcbCipherText, respectively. Esta consulta es eficaz y devuelve el tamaño sin realizar la encapsulación. Equivalently, use BCryptGetProperty to query the BCRYPT_KEM_SHARED_SECRET_LENGTH property of the algorithm or key handle, and the BCRYPT_KEM_CIPHERTEXT_LENGTH property of the key handle. Para los algoritmos KEM admitidos actualmente (ML-KEM), la longitud del secreto compartido es un tamaño constante para un algoritmo determinado y la longitud del texto cifrado KEM es un tamaño constante para un conjunto de parámetros determinado.

Requirements

Requirement Value
Cliente mínimo compatible Windows Insiders (compilación 27843): Comienza la compatibilidad con ML-KEM. [solo aplicaciones de escritorio]
Servidor mínimo admitido Windows Insiders (compilación 27843): Comienza la compatibilidad con ML-KEM. [solo aplicaciones de escritorio]
Library Bcrypt.lib
DLL Bcrypt.dll

See also

BCryptDecapsulate

BCryptGetProperty