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
Represents a symmetric key or an asymmetric key pair.
Syntax
var cryptographicKey = createKey(); var cryptographicKey = createSymmetricKey(); var cryptographicKey = importKeyPair(); var cryptographicKey = importPublicKey();
Attributes
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- VersionAttribute(NTDDI_WIN8)
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.
| Method | Description |
|---|---|
| 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.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets 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:
- AsymmetricKeyAlgorithmProvider
- KeyDerivationAlgorithmProvider
- MacAlgorithmProvider
- SymmetricKeyAlgorithmProvider
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] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 12/4/2012