Condividi tramite


KeyDerivationParameters.BuildForSP800108(IBuffer, IBuffer) Metodo

Definizione

Crea un oggetto KeyDerivationParameters da usare in una modalità contatore, la funzione di derivazione della chiave HMAC (Hash-Based Message Authentication Code).

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

Parametri

label
IBuffer

Buffer che specifica lo scopo per il materiale di chiave derivata.

context
IBuffer

Buffer che specifica informazioni correlate al materiale di chiave derivata. Ad esempio, il contesto può identificare le parti che derivano il materiale di chiave e, facoltativamente, un nonce noto dalle parti.

Restituisce

Fa riferimento ai parametri usati durante la derivazione della chiave.

Esempio

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

Commenti

È possibile usare i nomi degli algoritmi seguenti con la funzione OpenAlgorithm per aprire un provider di algoritmi SP800108 KDF:

Si applica a