Compartilhar via


NCryptEncapsulate 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 NCryptEncapsulate 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 criptografado KEM, retornando a chave secreta compartilhada e o texto criptografado KEM.

Syntax

NTSTATUS NCryptEncapsulate (
    [in]    NCRYPT_KEY_HANDLE hKey
    [out]   PBYTE             pbSecretKey,
    [in]    ULONG             cbSecretKey,
    [out]   ULONG             *pcbSecretKey,
    [out]   PBYTE             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.

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 criptografado 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 êxito ou a falha da função.

Os códigos de retorno possíveis incluem, mas não se limitam a, o seguinte.

Return Code Description
ERROR_SUCCESS A função foi bem-sucedida.
NTE_BAD_FLAGS The dwFlags parameter contains a value that is not valid.
NTE_INVALID_PARAMETER One or more required parameters (hKey, pcbSecretKey, pcbCipherText) is NULL, or one of the parameters has an invalid value.
NTE_BUFFER_TOO_SMALL An output buffer size (cbSecretKey, cbCipherText) is too small for the result of the encapsulation 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 NCryptEncapsulate with NULL values in pbSecretKey and pbCipherText. The required size will be returned in pcbSecretKey and pcbCipherText, respectively. Essa consulta é eficiente e retorna o tamanho sem executar o encapsulamento. Equivalently, use NCryptGetProperty to query the NCRYPT_KEM_SHARED_SECRET_LENGTH_PROPERTY property of the algorithm or key handle, and the NCRYPT_KEM_CIPHERTEXT_LENGTH_PROPERTY property of the key handle. Para algoritmos KEM com suporte no momento (ML-KEM), o comprimento do segredo compartilhado é um tamanho constante para um determinado algoritmo e o comprimento do texto criptografado KEM é um tamanho constante para um determinado conjunto de parâmetros.

Requirements

Requirement Value
Cliente mínimo suportado Windows Insiders (build 27843): O suporte para ML-KEM começa. [Somente aplicativos da área de trabalho]
Servidor mínimo compatível Windows Insiders (build 27843): O suporte para ML-KEM começa. [Somente aplicativos da área de trabalho]
Library Ncrypt.lib
DLL Ncrypt.dll

See also

NCryptDecapsulate

NCryptGetProperty

BCryptEncapsulate

BCryptDecapsulate