AsymmetricKeyAlgorithmProvider.CreateKeyPair | createKeyPair method

Applies to Windows and Windows Phone

Creates a public/private key pair.

Syntax


var cryptographicKey = asymmetricKeyAlgorithmProvider.createKeyPair(keySize);

Parameters

keySize

Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

Size, in bits, of the key. Typical key sizes are 512, 1024, 2048, or 4096 bits.

Return value

Type: CryptographicKey

Represents the asymmetric key pair.

Examples


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

    // Demonstrate use of the AlgorithmName property (not necessary to create a key pair).
    String strAlgName = objAlgProv.AlgorithmName;

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

    // Export the public key to a buffer for use by others.
    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.
    AsymmetricKeyAlgorithmApp.buffKeyPair = keyPair.Export();
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

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

 

 

Show:
© 2014 Microsoft