Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

KeyDerivationParameters.IterationCount | iterationCount property

Applies to Windows and Windows Phone

Retrieves the number of iterations used to derive the key. For more information, see BuildForPbkdf2.

Syntax


var iterationCount = keyDerivationParameters.iterationCount;

Property value

Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

Iteration count.

Remarks

The number of iterations is specified in the BuildForPbkdf2 method.

Examples


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

    // 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 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 iterationCountIn = 10000;

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

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

    // Demonstrate how to check the iteration count.
    UInt32 iterationCountOut = pbkdf2Params.IterationCount;

    // Demonstrate how to retrieve the parameters in a buffer.
    IBuffer buffParams = pbkdf2Params.KdfGenericBinary;

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


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Security.Cryptography.Core
Windows::Security::Cryptography::Core [C++]

Metadata

Windows.winmd

See also

KeyDerivationParameters

 

 

Show:
© 2014 Microsoft. All rights reserved.