Partilhar via


BCryptEncapsulate function

Note

Algumas informações referem-se a um produto de pré-lançamento que pode ser substancialmente modificado antes de ser lançado comercialmente. A Microsoft não oferece garantias, expressas ou implícitas, em relação às informações fornecidas aqui. O recurso descrito neste tópico está disponível em versões de pré-lançamento do Windows Insider Preview.

The BCryptEncapsulate function performs the Encapsulation operation of a Key Encapsulation Mechanism (KEM). Ele gera uma chave secreta compartilhada e a criptografa com a chave pública fornecida para produzir um texto cifrado KEM, retornando tanto a chave secreta compartilhada quanto o 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]

O identificador da chave a ser usada para a operação de encapsulamento. 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. Também é possível usar um identificador de chave privada para a operação de encapsulamento, pois os identificadores de chave privada KEM representam um par de chaves.

pbSecretKey[out]

Um ponteiro para um buffer que recebe a chave secreta compartilhada. 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]

Um ponteiro para um buffer que recebe o 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, deve ser zero.

Return value

Retorna um código de status que indica o sucesso ou falha da função.

Os códigos de devolução possíveis incluem, mas não estão limitados a, o seguinte.

Return Code Description
STATUS_SUCCESS A função foi bem-sucedida.
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. Essa consulta é eficiente e retorna o tamanho sem executar o encapsulamento. 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 algoritmos KEM atualmente suportados (ML-KEM), o comprimento do segredo compartilhado é um tamanho constante para um determinado algoritmo e o comprimento do texto cifrado KEM é um tamanho constante para um determinado conjunto de parâmetros.

Requirements

Requirement Value
Cliente mínimo suportado Windows Insiders (compilação 27843): O suporte para ML-KEM começa. [Apenas aplicações de ambiente de trabalho]
Servidor mínimo suportado Windows Insiders (compilação 27843): O suporte para ML-KEM começa. [Apenas aplicações de ambiente de trabalho]
Library Bcrypt.lib
DLL Bcrypt.dll

See also

BCryptDecapsulate

BCryptGetProperty