CryptographicEngine.DeriveKeyMaterial 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用密钥派生函数从另一个密钥派生密钥。 有关详细信息,请参阅 KeyDerivationAlgorithmProvider 和 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
	参数
- key
 - CryptographicKey
 
用于派生的对称密钥或密钥。
- parameters
 - KeyDerivationParameters
 
派生参数。 参数因使用的 KDF 算法类型而异。
- desiredKeySize
 - 
				
				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;
}
	注解
派生密钥要求使用 KeyDerivationAlgorithmProvider 和 KeyDerivationParameters 类。 可以使用以下关键派生函数:
有关包含以下代码示例的完整示例,请参阅 KeyDerivationAlgorithmProvider 类。