i've got following C# code for doing what i asked for in subject:
public static void ExportCertificatesToFile(string FileName)
{
stringBuilder builder = new StringBuilder();
X509Store storeMy = new X509Store(StoreName.My);
storeMy.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in storeMy.Certificates)
{
builder.AppendLine("-----BEGIN CERTIFICATE-----");
builder.AppendLine(Convert.ToBase64String(cert.Export(X509ContentType.Cert), Base64FormattingOptions.InsertLineBreaks));
builder.AppendLine("-----END CERTIFICATE-----");
}
storeMy.Close();
File.WriteAllText(FileName, builder.ToString());
}
Exactly that i want to archieve with Delphi using CryptoAPI (JwaWinCrypt.pas) I've tried following code:
procedure TForm1.Button1Click(Sender: TObject);
var
hStore: HCERTSTORE;
CertContext: PCertContext;
pszString: PAnsiChar;
pchString: Cardinal;
begin
hStore := CertOpenSystemStore(0, PChar('MY'));
try
CertContext := CertEnumCertificatesInStore(hStore, nil);
while CertContext <> nil do
begin
pszString := '';
pchString := 0;
CryptBinaryToString(CertContext.pbCertEncoded, CertContext.cbCertEncoded, CRYPT_STRING_BASE64, pszString, pchString);
ShowMessage(StrPas(pszString));
CertContext := CertEnumCertificatesInStore(hStore, CertContext);
end;
finally
CertCloseStore(hStore, 0);
end;
end;
Problem is that ShowMessage shows nothing, the string is empty. Has someone an idea what i do wrong?