Load a private key from a file and associate it with the public certificate

1. Importing a private key and a public-key certificate, assigning the imported key to the selected certificate, installing the resulting private-key certificate to the personal certificate storage.
clCertificateStore1.Open('MY');

clCertificateStore1.CSP := MS_ENH_RSA_AES_PROV;
clCertificateStore1.ProviderType := PROV_RSA_AES;

clCertificateStore1.ImportKey('private-key-name-1234567890', 'privatekey.pem');
clCertificateStore1.ImportFromCER('cert.cer');
cert := clCertificateStore1.CertificateByThumbprint('3214a0.........');
cert.SetPrivateKey('private-key-name-1234567890', clCertificateStore1.CSP, clCertificateStore1.ProviderType, ktKeyExchange);
clCertificateStore1.Install(cert);
 
2. Exporting the private key from the selected certificate and saving the key to a file.
clCertificateStore1.Open('MY');

clCertificateStore1.CSP := MS_ENH_RSA_AES_PROV;
clCertificateStore1.ProviderType := PROV_RSA_AES;

cert := clCertificateStore1.CertificateByThumbprint('3214a0.........');
clCertificateStore1.ExportKey(cert.PrivateKey, 'privatekey.pem');
 

Add Feedback