Share via


CryptographicEngine.Sign(CryptographicKey, IBuffer) Método

Definição

Assina conteúdo digital. Para obter mais informações, consulte MACs, hashes e assinaturas.

public:
 static IBuffer ^ Sign(CryptographicKey ^ key, IBuffer ^ data);
 static IBuffer Sign(CryptographicKey const& key, IBuffer const& data);
public static IBuffer Sign(CryptographicKey key, IBuffer data);
function sign(key, data)
Public Shared Function Sign (key As CryptographicKey, data As IBuffer) As IBuffer

Parâmetros

key
CryptographicKey

Chave usada para assinatura.

data
IBuffer

Dados a serem assinados.

Retornos

A assinatura dos dados.

Exemplos

public IBuffer SampleCreateHMAC(
    String strMsg,
    String strAlgName,
    out IBuffer buffMsg,
    out CryptographicKey hmacKey)
{
    // Create a MacAlgorithmProvider object for the specified algorithm.
    MacAlgorithmProvider objMacProv = MacAlgorithmProvider.OpenAlgorithm(strAlgName);

    // Create a buffer that contains the message to be signed.
    BinaryStringEncoding encoding = BinaryStringEncoding.Utf8;
    buffMsg = CryptographicBuffer.ConvertStringToBinary(strMsg, encoding);

    // Create a key to be signed with the message.
    IBuffer buffKeyMaterial = CryptographicBuffer.GenerateRandom(objMacProv.MacLength);
    hmacKey = objMacProv.CreateKey(buffKeyMaterial);

    // Sign the key and message together.
    IBuffer buffHMAC = CryptographicEngine.Sign(hmacKey, buffMsg);

    // Verify that the HMAC length is correct for the selected algorithm
    if (buffHMAC.Length != objMacProv.MacLength)
    {
        throw new Exception("Error computing digest");
    }

    // Return the HMAC.
    return buffHMAC;
}

Comentários

Se a chave for uma chave persistente e a operação exigir interface do usuário ou demorar muito, use o método SignAsync .

Para obter mais informações sobre como assinar dados digitais, consulte MACs, hashes e assinaturas.

Aplica-se a