Language

CryptographicEngine.Sign(CryptographicKey, IBuffer) メソッド

定義

デジタル コンテンツに署名します。 詳細については、「 MAC、ハッシュ、署名」を参照してください。

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

パラメーター

key
CryptographicKey

署名に使用されるキー。

data
IBuffer

署名するデータ。

戻り値

データの署名。

例

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;
}

注釈

キーが永続化されたキーであり、操作に UI が必要な場合、または時間がかかる場合は、代わりに SignAsync メソッドを使用します。

デジタル データへの署名の詳細については、「 MAC、ハッシュ、署名」を参照してください。

適用対象