Importing a Certificate into the Data Vault

Obtain a certificate reference and store it in a password-protected data vault to use for X.509 certificate authentication.

The difference between importing a certificate from a system store or a file directory is determined by how you obtain the CertificateStore object. In either case, only a label and password are required to import a certificate blob, which is a digitally signed copy of the public X.509 certificate.

//Obtain a reference to the certificate store
CertificateStore myStore = CertificateStore.GetDefault();

//List all certificate labels from the certificate store
StringList labels = myStore.CertificateLabels();

//List the certificate labels filtered by subject
String filter1 = "Sybase";
labels = myStore.CertificateLabels(filter1, null);

//Get a LoginCertificate from the certificate store
string aLabel = ... //ask user to select a label
string password = ... //prompt user for password
LoginCertificate lc = myStore.GetSignedCertificate(aLabel, password);

//Save/Load/Delete...LoginCertificate 
//Create or lookup a data vault
DataVault vault = null;
if (!DataVault.VaultExists("myVault"))
{
    vault = DataVault.CreateVault("myVault", "password", "salt");
}
else
{
    vault = DataVault.GetVault("myVault");
}