Share via


CryptographicKey Clase

Definición

Representa una clave simétrica o un par de claves asimétricas.

public ref class CryptographicKey sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class CryptographicKey final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class CryptographicKey
Public NotInheritable Class CryptographicKey
Herencia
Object Platform::Object IInspectable CryptographicKey
Atributos

Requisitos de Windows

Familia de dispositivos
Windows 10 (se introdujo en la versión 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (se introdujo en la versión v1.0)

Ejemplos

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

namespace SampleCryptographicKey
{
    sealed partial class CryptographicKeyApp : Application
    {
        static IBuffer buffKeyPair;

        public CryptographicKeyApp()
        {
            // Initialize the application.
            this.InitializeComponent();

            // Create an asymmetric key pair.
            String strAsymmetricAlgName = AsymmetricAlgorithmNames.RsaPkcs1;
            UInt32 asymmetricKeyLength = 512;
            IBuffer buffPublicKey = this.SampleCreateAsymmetricKeyPair(
                strAsymmetricAlgName,
                asymmetricKeyLength);
        }

        public IBuffer SampleCreateAsymmetricKeyPair(
            String strAsymmetricAlgName,
            UInt32 keyLength)
        {
            // Open the algorithm provider for the specified asymmetric algorithm.
            AsymmetricKeyAlgorithmProvider objAlgProv = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(strAsymmetricAlgName);

            // Create an asymmetric key pair.
            CryptographicKey keyPair = objAlgProv.CreateKeyPair(keyLength);

            // Export the public key to a buffer for use by others.
            IBuffer buffPublicKey = keyPair.ExportPublicKey();

            // You should keep your private key (embedded in the key pair) secure. For  
            // the purposes of this example, however, we're just copying it into a
            // static class variable for later use during decryption.
            CryptographicKeyApp.buffKeyPair = keyPair.Export();

            // Retrieve the size of the key pair.
            UInt32 lengthKeyPair = keyPair.KeySize;

            // Return the public key.
            return buffPublicKey;
        }
    }
}

Comentarios

Se crea un objeto CryptographicKey cuando se usan métodos que crean o importan claves en las siguientes clases:

Propiedades

KeySize

Obtiene el tamaño, en bits, de la clave.

Métodos

Export()

Exporta el par de claves a un búfer.

Export(CryptographicPrivateKeyBlobType)

Exporta el par de claves a un búfer dado un formato especificado.

ExportPublicKey()

Exporta una clave pública a un búfer.

ExportPublicKey(CryptographicPublicKeyBlobType)

Exporta una clave pública a un búfer dado un formato especificado.

Se aplica a

Consulte también