共用方式為


KeyDerivationParameters.BuildForPbkdf2(IBuffer, UInt32) 方法

定義

建立 KeyDerivationParameters 物件,以用於密碼型金鑰衍生函式 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

參數

pbkdf2Salt
IBuffer

salt,要與多個反復專案中的密碼合併的隨機或虛擬隨機值。 salt 是用來在單獨使用密碼取得的內容上方增加 entropy。

iterationCount
UInt32

unsigned int

uint32_t

要用來衍生金鑰的反復專案數目。

傳回

參考金鑰衍生期間所使用的參數。

範例

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

備註

您可以使用下列演算法名稱搭配 OpenAlgorithm 函式來開啟 PBKDF2 演算法提供者:

適用於