Condividi tramite


KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) Metodo

Definizione

Crea un oggetto KeyDerivationParameters da usare nella funzione di derivazione della chiave basata su password 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

Parametri

pbkdf2Salt
IBuffer

Il sale, un valore casuale o pseudorandom da combinare con la password in più iterazioni. Un sale viene usato per aumentare l'entropia sopra ciò che può essere ottenuto usando una password da sola.

iterationCount
UInt32

unsigned int

uint32_t

Numero di iterazioni da usare per derivare una chiave.

Restituisce

Fa riferimento ai parametri usati durante la derivazione della chiave.

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

È possibile usare i nomi degli algoritmi seguenti con la funzione OpenAlgorithm per aprire un provider di algoritmi PBKDF2:

Si applica a