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.

CryptographicEngine.DeriveKeyMaterial | deriveKeyMaterial method

Applies to Windows and Windows Phone

Derives a key from another key by using a key derivation function. For more information, see the KeyDerivationAlgorithmProvider and KeyDerivationParameters classes.

Syntax


var iBuffer = Windows.Security.Cryptography.Core.CryptographicEngine.deriveKeyMaterial(key, parameters, desiredKeySize);

Parameters

key

Type: CryptographicKey

The symmetric or secret key used for derivation.

parameters

Type: KeyDerivationParameters

Derivation parameters. The parameters vary depending on the type of KDF algorithm used.

desiredKeySize

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

Requested size, in bytes, of the derived key.

Return value

Type: IBuffer

Buffer that contains the derived key.

Remarks

Deriving keys requires that you use the KeyDerivationAlgorithmProvider and KeyDerivationParameters classes. The following key derivation functions can be used:

For a complete sample that contains the following code example, see the KeyDerivationAlgorithmProvider class.

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


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

CryptographicEngine
KeyDerivationAlgorithmProvider
KeyDerivationParameters

 

 

Show:
© 2014 Microsoft. All rights reserved.