Language

KeyChain.GetX509Certificate2WithPrivateKey(Context, String) Method

Definition

Retrieves an X509Certificate2 with its associated private key from the Android system KeyChain.

public static System.Security.Cryptography.X509Certificates.X509Certificate2? GetX509Certificate2WithPrivateKey(Android.Content.Context context, string alias);
static member GetX509Certificate2WithPrivateKey : Android.Content.Context * string -> System.Security.Cryptography.X509Certificates.X509Certificate2

Parameters

context
Context

The Android context used to access the KeyChain.

alias
String

The alias of the private key and certificate chain to retrieve.

Returns

An X509Certificate2 containing the certificate and private key, or null if the private key or certificate chain is not available for the given alias.

Remarks

This method combines GetPrivateKey(Context, String) and GetCertificateChain(Context, String) into a single call that returns a .NET X509Certificate2 suitable for use with ClientCertificates or other TLS APIs.

Applies to