KeyDerivationAlgorithmProvider Klasse

Definition

Stellt einen Anbieter von Schlüsselableitungsalgorithmus dar.

public ref class KeyDerivationAlgorithmProvider sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class KeyDerivationAlgorithmProvider final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class KeyDerivationAlgorithmProvider
Public NotInheritable Class KeyDerivationAlgorithmProvider
Vererbung
Object Platform::Object IInspectable KeyDerivationAlgorithmProvider
Attribute

Windows-Anforderungen

Gerätefamilie
Windows 10 (eingeführt in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v1.0)

Beispiele


using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage.Streams;

namespace SampleKeyDerivationAlgorithm
{
    sealed partial class SampleKeyDerivationProviderApp : Application
    {
        public SampleKeyDerivationProviderApp()
        {
            // Initialize the Application.
            this.InitializeComponent();

            // Derive key material from a password-based key derivation function.
            String strKdfAlgName = KeyDerivationAlgorithmNames.Pbkdf2Sha256;
            UInt32 targetKeySize = 32;
            UInt32 iterationCount = 10000;
            IBuffer buffKeyMatl = this.SampleDeriveKeyMaterialPbkdf(
                strKdfAlgName,
                targetKeySize,
                iterationCount);

            // Create a key.
            CryptographicKey key = this.SampleCreateKDFKey(
                strKdfAlgName,
                buffKeyMatl);
        }

        public IBuffer SampleDeriveKeyMaterialPbkdf(
            String strAlgName,
            UInt32 targetKeySize,
            UInt32 iterationCount)
        {

            // Open the specified algorithm.
            KeyDerivationAlgorithmProvider objKdfProv = KeyDerivationAlgorithmProvider.OpenAlgorithm(strAlgName);

            // Demonstrate how to retrieve the algorithm name.
            String strAlgUsed = objKdfProv.AlgorithmName;

            // 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);

            // 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 keyMaterial = CryptographicEngine.DeriveKeyMaterial(
                keyOriginal,
                pbkdf2Params,
                targetKeySize);

            // Demonstrate checking the iteration count.
            UInt32 iterationCountOut = pbkdf2Params.IterationCount;

            // Demonstrate returning the derivation parameters to a buffer.
            IBuffer buffParams = pbkdf2Params.KdfGenericBinary;

            // return the KDF key material.
            return keyMaterial;
        }

        public CryptographicKey SampleCreateKDFKey(
            String strAlgName,
            IBuffer buffKeyMaterial)
        {
            // Create a KeyDerivationAlgorithmProvider object and open the specified algorithm.
            KeyDerivationAlgorithmProvider objKdfAlgProv = KeyDerivationAlgorithmProvider.OpenAlgorithm(strAlgName);

            // Create a key by using the KDF parameters.
            CryptographicKey key = objKdfAlgProv.CreateKey(buffKeyMaterial);

            return key;
        }
    }
}

Hinweise

Wenn zwei oder mehr Parteien einen geheimen symmetrischen Schlüssel gemeinsam nutzen, müssen häufig zusätzliche Schlüssel für die Verwendung in kryptografischen Vorgängen abgeleitet werden. Häufig ist es auch erforderlich, dass ein vertrauenswürdiger Drittanbieter verschiedene kryptografische Schlüssel aus einem einzelnen master Schlüssel ableiten kann. Schlüsselableitungsfunktionen werden verwendet, um diese zusätzlichen Schlüssel abzuleiten.

Sie können die statische DeriveKeyMaterial-Methode in der CryptographicEngine-Klasse und die folgenden Methoden in der KeyDerivationParameters-Klasse verwenden, um einen Schlüssel abzuleiten.

Methode BESCHREIBUNG
BuildForPbkdf2 Erstellt ein KeyDerivationParameters-Objekt zur Verwendung in der kennwortbasierten Schlüsselableitungsfunktion 2 (PBKDF2).
BuildForSP800108 Erstellt ein KeyDerivationParameters-Objekt für die Verwendung in einem Zählermodus, einer HMAC-Schlüsselableitungsfunktion (Hash-based Message Authentication Code).
BuildForSP80056a Erstellt ein KeyDerivationParameters-Objekt zur Verwendung in der Schlüsselableitungsfunktion SP800-56A.

Sie erstellen ein KeyDerivationAlgorithmProvider-Objekt, indem Sie die statische OpenAlgorithm-Methode aufrufen.

Eigenschaften

AlgorithmName

Ruft den Namen des KDF-Algorithmus (Open Key Derivation Function) ab.

Methoden

CreateKey(IBuffer)

Erstellt einen KDF-Schlüssel.

OpenAlgorithm(String)

Erstellt eine instance der KeyDerivationAlgorithmProvider-Klasse und öffnet den angegebenen Algorithmus zur Verwendung.

Gilt für:

Weitere Informationen