Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CryptographicKey class

Applies to Windows and Windows Phone

Represents a symmetric key or an asymmetric key pair.

Syntax


public sealed class CryptographicKey

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Members

The CryptographicKey class has these types of members:

Methods

The CryptographicKey class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Export() Exports the key pair to a buffer.
Export(CryptographicPrivateKeyBlobType) Exports the key pair to a buffer given a specified format.
ExportPublicKey() Exports a public key to a buffer.
ExportPublicKey(CryptographicPublicKeyBlobType) Exports a public key to a buffer given a specified format.

 

Properties

The CryptographicKey class has these properties.

PropertyAccess typeDescription

KeySize

Read-onlyGets the size, in bits, of the key.

 

Remarks

A CryptographicKey object is created when you use methods that create or import keys in the following classes:

Examples


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


Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Security.Cryptography.Core
Windows::Security::Cryptography::Core [C++]

Metadata

Windows.winmd

See also

AsymmetricKeyAlgorithmProvider
SymmetricKeyAlgorithmProvider

 

 

Show:
© 2014 Microsoft