CryptographicKey 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示對稱金鑰或非對稱金鑰組。
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
- 繼承
- 屬性
Windows 需求
裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
範例
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;
}
}
}
備註
當您使用在下列類別中建立或匯入金鑰的方法時,就會建立 CryptographicKey 物件:
- AsymmetricKeyAlgorithmProvider
- KeyDerivationAlgorithmProvider
- MacAlgorithmProvider
- SymmetricKeyAlgorithmProvider
屬性
KeySize |
取得金鑰的大小 (以位元為單位)。 |
方法
Export() |
將金鑰組匯出至緩衝區。 |
Export(CryptographicPrivateKeyBlobType) |
將金鑰組匯出至指定格式的緩衝區。 |
ExportPublicKey() |
將公開金鑰匯出至緩衝區。 |
ExportPublicKey(CryptographicPublicKeyBlobType) |
將公開金鑰匯出至指定格式的緩衝區。 |