KeyDerivationParameters.BuildForSP800108(IBuffer, IBuffer) 方法

定義

建立 KeyDerivationParameters 物件,以用於計數器模式、雜湊型訊息驗證程式代碼 (HMAC) 金鑰衍生函式。

public:
 static KeyDerivationParameters ^ BuildForSP800108(IBuffer ^ label, IBuffer ^ context);
 static KeyDerivationParameters BuildForSP800108(IBuffer const& label, IBuffer const& context);
public static KeyDerivationParameters BuildForSP800108(IBuffer label, IBuffer context);
function buildForSP800108(label, context)
Public Shared Function BuildForSP800108 (label As IBuffer, context As IBuffer) As KeyDerivationParameters

參數

label
IBuffer

指定衍生索引鍵材質用途的緩衝區。

context
IBuffer

指定衍生索引鍵材質相關資訊的緩衝區。 例如,內容可以識別衍生索引鍵資料的合作物件,並選擇性地識別由合作物件知道的 Nonce。

傳回

參考金鑰衍生期間所使用的參數。

範例

public void SampleDeriveFromSP800108()
{
    // Create a string that contains the algorithm name.
    String strAlgName = KeyDerivationAlgorithmNames.Sp800108CtrHmacSha256;

    // Open the specified algorithm.
    KeyDerivationAlgorithmProvider objKdfProv = KeyDerivationAlgorithmProvider.OpenAlgorithm(strAlgName);

    // Specify the requested size, in bytes, of the derived key. 
    UInt32 targetSize = 32;

    // Create a buffer that contains the label value.
    String strPurpose = "Purpose";
    IBuffer buffLabel = CryptographicBuffer.ConvertStringToBinary(strPurpose, BinaryStringEncoding.Utf8);

    // Create a buffer that contains the context value.
    byte[] Nonce = { 1, 1, 0, 0, 0, 0, 0, 0};
    IBuffer buffContext = CryptographicBuffer.CreateFromByteArray(Nonce);

    // Create the derivation parameters.
    KeyDerivationParameters kdf800108Params = KeyDerivationParameters.BuildForSP800108(buffLabel, buffContext);

    // Create a secret value.
    IBuffer buffSecret = CryptographicBuffer.GenerateRandom(32);

    // Create a key from the secret value.
    CryptographicKey keyOriginal = objKdfProv.CreateKey(buffSecret);

    // Derive a key based on the original key and the derivation parameters.
    IBuffer keyDerived = CryptographicEngine.DeriveKeyMaterial(
        keyOriginal,
        kdf800108Params,
        targetSize);

    // Encode the key to a hexadecimal value (for display)
    String strKeyHex = CryptographicBuffer.EncodeToHexString(keyDerived);
}

備註

您可以使用下列演算法名稱搭配 OpenAlgorithm 函式來開啟 SP800108 KDF 演算法提供者:

適用於