KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) Method

Definition

Creates a KeyDerivationParameters object for use in the password-based key derivation function 2 (PBKDF2).

public : static KeyDerivationParameters BuildForPbkdf2(IBuffer pbkdf2Salt, unsigned int iterationCount)
static KeyDerivationParameters BuildForPbkdf2(IBuffer pbkdf2Salt, uint32_t iterationCount) const;
public static KeyDerivationParameters BuildForPbkdf2(IBuffer pbkdf2Salt, UInt32 iterationCount)
Public Shared Function BuildForPbkdf2(pbkdf2Salt As IBuffer, iterationCount As UInt32) As KeyDerivationParameters
var keyDerivationParameters = Windows.Security.Cryptography.Core.KeyDerivationParameters.buildForPbkdf2(pbkdf2Salt, iterationCount);

Parameters

pbkdf2Salt
IBuffer IBuffer IBuffer

The salt, a random or pseudorandom value to be combined with the password in multiple iterations. A salt is used to increase entropy above what can be obtained from using a password alone.

iterationCount
UInt32 UInt32 UInt32

Number of iterations to be used to derive a key.

Returns

Examples

public String SampleDeriveFromPbkdf(
    String strAlgName,
    UInt32 targetSize)
{
    // Open the specified algorithm.
    KeyDerivationAlgorithmProvider objKdfProv = KeyDerivationAlgorithmProvider.OpenAlgorithm(strAlgName);

    // Create a buffer that contains the secret used during derivation.
    String strSecret = "MyPassword";
    IBuffer buffSecret = CryptographicBuffer.ConvertStringToBinary(strSecret, BinaryStringEncoding.Utf8);

    // Create a random salt value.
    IBuffer buffSalt = CryptographicBuffer.GenerateRandom(32);

    // Specify the number of iterations to be used during derivation.
    UInt32 iterationCount = 10000;

    // Create the derivation parameters.
    KeyDerivationParameters pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, iterationCount);

    // 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,
        pbkdf2Params,
        targetSize);

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

    // Return the encoded string
    return strKeyHex;
}

Remarks

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