Property Value
System.String
Description: Gets or sets a friendly name for the certificate. This name is not part of the X.509 standard.
Property Type: String
The FriendlyName property can be used to store a descriptive name for the certificate. This is useful for distinguishing between multiple certificates, especially when they have the same subject or issuer.
When you retrieve a certificate from a certificate store, the FriendlyName property will be empty unless it was explicitly set. You can set this property to any string value.
The following example demonstrates how to set and retrieve the FriendlyName property of an X509Certificate2 object.
using System;
using System.Security.Cryptography.X509Certificates;
public class CertificateFriendlyNameExample
{
public static void Main(string[] args)
{
// Assume 'myCertificate' is an existing X509Certificate2 object.
// For demonstration, we'll create a dummy one.
// In a real scenario, you would load a certificate from a store or file.
X509Certificate2 myCertificate = new X509Certificate2();
myCertificate.Import("path/to/your/certificate.pfx", "your_password", X509KeyStorageFlags.Exportable); // Example of loading
// Set a friendly name for the certificate
myCertificate.FriendlyName = "My Development Server Certificate";
Console.WriteLine($"Friendly Name set: {myCertificate.FriendlyName}");
// You can also retrieve the friendly name later
string retrievedName = myCertificate.FriendlyName;
Console.WriteLine($"Friendly Name retrieved: {retrievedName}");
// In a real application, you might store this certificate with its friendly name
// in a certificate store or manage it in a collection.
}
}