CryptographicEngine.DeriveKeyMaterial Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Deriva una chiave da un'altra chiave usando una funzione di derivazione chiave. Per altre informazioni, vedere le classi KeyDerivationAlgorithmProvider e 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
Parametri
- key
- CryptographicKey
Chiave simmetrica o privata usata per derivazione.
- parameters
- KeyDerivationParameters
Parametri di derivazione. I parametri variano a seconda del tipo di algoritmo KDF usato.
- desiredKeySize
-
UInt32
unsigned int
uint32_t
Dimensioni richieste, in byte, della chiave derivata.
Restituisce
Buffer contenente la chiave derivata.
Esempio
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;
}
Commenti
Per la derivazione delle chiavi è necessario usare le classi KeyDerivationAlgorithmProvider e KeyDerivationParameters . È possibile usare le funzioni di derivazione chiave seguenti:
Per un esempio completo contenente l'esempio di codice seguente, vedere la classe KeyDerivationAlgorithmProvider .