Share via


CryptographicEngine.DeriveKeyMaterial Méthode

Définition

Dérive une clé d’une autre clé à l’aide d’une fonction de dérivation de clé. Pour plus d’informations, consultez les classes KeyDerivationAlgorithmProvider et KeyDerivationParameters .

public:
 static IBuffer ^ DeriveKeyMaterial(CryptographicKey ^ key, KeyDerivationParameters ^ parameters, unsigned int desiredKeySize);
 static IBuffer DeriveKeyMaterial(CryptographicKey const& key, KeyDerivationParameters const& parameters, uint32_t const& desiredKeySize);
public static IBuffer DeriveKeyMaterial(CryptographicKey key, KeyDerivationParameters parameters, uint desiredKeySize);
function deriveKeyMaterial(key, parameters, desiredKeySize)
Public Shared Function DeriveKeyMaterial (key As CryptographicKey, parameters As KeyDerivationParameters, desiredKeySize As UInteger) As IBuffer

Paramètres

key
CryptographicKey

Clé symétrique ou secrète utilisée pour la dérivation.

parameters
KeyDerivationParameters

Paramètres de dérivation. Les paramètres varient en fonction du type d’algorithme KDF utilisé.

desiredKeySize
UInt32

unsigned int

uint32_t

Taille demandée, en octets, de la clé dérivée.

Retours

Mémoire tampon qui contient la clé dérivée.

Exemples

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

Remarques

La dérivation de clés nécessite l’utilisation des classes KeyDerivationAlgorithmProvider et KeyDerivationParameters . Les fonctions de dérivation de clé suivantes peuvent être utilisées :

Pour obtenir un exemple complet contenant l’exemple de code suivant, consultez la classe KeyDerivationAlgorithmProvider .

S’applique à

Voir aussi