KeyDerivationParameters.BuildForSP800108(IBuffer, IBuffer) Method

Definition

Creates a KeyDerivationParameters object for use in a counter mode, hash-based message authentication code (HMAC) key derivation function.

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

Parameters

label
IBuffer

Buffer that specifies the purpose for the derived keying material.

context
IBuffer

Buffer that specifies information related to the derived keying material. For example, the context can identify the parties who are deriving the keying material and, optionally, a nonce known by the parties.

Returns

Refers to the parameters used during key derivation.

Examples

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

Remarks

You can use the following algorithm names with the OpenAlgorithm function to open a SP800108 KDF algorithm provider:

Applies to