Dela via


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 const& pbkdf2Salt, uint32_t const& iterationCount);
public static KeyDerivationParameters BuildForPbkdf2(IBuffer pbkdf2Salt, uint iterationCount);
function buildForPbkdf2(pbkdf2Salt, iterationCount)
Public Shared Function BuildForPbkdf2 (pbkdf2Salt As IBuffer, iterationCount As UInteger) As KeyDerivationParameters

Parameters

pbkdf2Salt
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

unsigned int

uint32_t

Number of iterations to be used to derive a key.

Returns

Refers to the parameters used during key derivation.

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:

Applies to