Bring Your Own Key — 10 Providers

All providers implement the IsgcKeyProvider interface — the same signing code works against local files, smart cards, HSMs, cloud KMS, or remote QTSPs. Switch with one line.

Local Files (PFX, PEM)
Hardware (PKCS#11)
Cloud KMS (Azure, AWS, GCP)
QTSPs (Certum, CSC v2)

TsgcPFXKeyProvider

PFX / PKCS#12 files. Local password-protected key. Best for development, small deployments, and any workflow where the certificate ships as a single .pfx/.p12 file.

  • Imported via Windows CNG with PKCS12_PREFER_CNG_KSP — SHA-256/384/512 signing works regardless of the original CSP.
  • Multi-cert .pfx files are walked automatically until the cert with the private key is found.
pfx.pas
var
  vPFX: TsgcPFXKeyProvider;
begin
  vPFX := TsgcPFXKeyProvider.Create(nil);
  try
    vPFX.FileName := 'certificate.pfx';
    vPFX.Password := 'mypassword';
    vPFX.LoadFromFile;
    // vSigner.KeyProvider := vPFX;
  finally
    vPFX.Free;
  end;
end;

TsgcPEMKeyProvider

PEM files. Encrypted PKCS#8 with native PBES2 / PBKDF2 / AES-CBC support, plus the legacy RSA private-key DEK-Info format. Best for OpenSSL-based pipelines.

  • BEGIN CERTIFICATE, BEGIN RSA PRIVATE KEY, BEGIN PRIVATE KEY, BEGIN ENCRYPTED PRIVATE KEY all supported.
  • Combined PEMs (cert + key in one file) are detected automatically — leave PrivateKeyFile empty.
pem.pas
var
  vPEM: TsgcPEMKeyProvider;
begin
  vPEM := TsgcPEMKeyProvider.Create(nil);
  try
    vPEM.CertificateFile := 'cert.pem';
    vPEM.PrivateKeyFile  := 'key.pem';
    vPEM.PrivateKeyPassword := 'secret';
    vPEM.LoadFromFile;
    // vSigner.KeyProvider := vPEM;
  finally
    vPEM.Free;
  end;
end;

TsgcWindowsCertStoreProvider

Windows Certificate Store. Local-machine and current-user stores. Best for desktop apps using existing AD-issued certificates, or any deployment where Windows already manages the cert lifecycle.

  • Signing happens via Windows CNG — the private key never leaves the store.
  • Selection by subject CN substring or by SHA-1 thumbprint.
winstore.pas
var
  vStore: TsgcWindowsCertStoreProvider;
begin
  vStore := TsgcWindowsCertStoreProvider.Create(nil);
  try
    vStore.StoreName := 'MY';
    vStore.StoreLocation := cslCurrentUser;
    vStore.SelectCertificateBySubject('My Company');
    // vSigner.KeyProvider := vStore;
  finally
    vStore.Free;
  end;
end;

TsgcPKCS11Provider

PKCS#11 / Hardware Tokens. Smart cards, USB tokens, HSMs — SafeNet, YubiKey, Nitrokey, Thales. Required for Qualified Electronic Signatures in most EU jurisdictions.

  • CKM_RSA_PKCS and CKM_ECDSA_SHA256 mechanisms supported.
  • EnumerateSlots / EnumerateCertificates helpers for picking the right slot at runtime.
pkcs11.pas
var
  vTok: TsgcPKCS11Provider;
begin
  vTok := TsgcPKCS11Provider.Create(nil);
  try
    vTok.LibraryPath := 'C:\token\pkcs11.dll';
    vTok.SlotIndex := 0;
    vTok.PIN := '1234';
    vTok.CertificateLabel := 'MyCert';
    vTok.Connect;
    // vSigner.KeyProvider := vTok;
  finally
    vTok.Free;
  end;
end;

TsgcAzureTrustedSigningProvider

Azure Trusted Signing. Microsoft's qualified code-signing service. Authenticode without buying an EV cert — Microsoft owns the certificate and provisions the signing key for you.

  • OAuth2 client credentials — Tenant ID + Client ID + Client Secret.
  • Private keys live entirely in Azure, never on the build agent.
azure-ts.pas
var
  vAzure: TsgcAzureTrustedSigningProvider;
begin
  vAzure := TsgcAzureTrustedSigningProvider.Create(nil);
  try
    vAzure.TenantId := 'your-tenant-id';
    vAzure.ClientId := 'your-client-id';
    vAzure.ClientSecret := 'your-client-secret';
    vAzure.AccountName := 'mySigningAccount';
    vAzure.CertificateProfileName := 'default';
    vAzure.Connect;
    // vSigner.KeyProvider := vAzure;
  finally
    vAzure.Free;
  end;
end;

TsgcAWSKMSKeyProvider

AWS Key Management Service. Amazon's HSM-backed key custody service. Pair with an AWS-issued cert for in-cloud signing without exposing the private key.

  • AWS Signature Version 4 authentication, computed in-process.
  • KeyId accepts key ID, key ARN, or alias ARN.
aws-kms.pas
var
  vAWS: TsgcAWSKMSKeyProvider;
begin
  vAWS := TsgcAWSKMSKeyProvider.Create(nil);
  try
    vAWS.AccessKeyId := 'AKIAIOSFODNN7EXAMPLE';
    vAWS.SecretAccessKey := 'wJalrXUtnFEMI/K7MDENG/...';
    vAWS.Region := 'us-east-1';
    vAWS.KeyId := 'arn:aws:kms:us-east-1:...:key/my-key';
    vAWS.Connect;
    // vSigner.KeyProvider := vAWS;
  finally
    vAWS.Free;
  end;
end;

TsgcGCloudKMSKeyProvider

Google Cloud KMS. Same operational model as AWS KMS. Service-account JSON file authenticates via JWT exchange to OAuth2 access token, then signs through the Cloud KMS API.

  • ProjectId + Location + KeyRing + Key + Version — matches the GCP resource hierarchy 1:1.
  • Asymmetric KMS keys only — HSM-backed when available, software-protected otherwise.
gcloud-kms.pas
var
  vGCloud: TsgcGCloudKMSKeyProvider;
begin
  vGCloud := TsgcGCloudKMSKeyProvider.Create(nil);
  try
    vGCloud.ProjectId := 'my-project';
    vGCloud.LocationId := 'global';
    vGCloud.KeyRingId := 'my-key-ring';
    vGCloud.KeyId := 'my-signing-key';
    vGCloud.KeyVersion := '1';
    vGCloud.ServiceAccountJSON := 'C:\keys\sa.json';
    vGCloud.Connect;
    // vSigner.KeyProvider := vGCloud;
  finally
    vGCloud.Free;
  end;
end;

TsgcHashiCorpVaultKeyProvider

HashiCorp Vault. Vault's Transit secrets engine performs the signing. Best for self-hosted, policy-driven key custody where Vault is already part of the stack.

  • Transit engine manages the key only — supply the certificate via SetCertificateFromFile.
  • Token-based auth; mount path defaults to 'transit'.
vault.pas
var
  vVault: TsgcHashiCorpVaultKeyProvider;
begin
  vVault := TsgcHashiCorpVaultKeyProvider.Create(nil);
  try
    vVault.VaultAddress := 'https://vault.example.com:8200';
    vVault.Token := 's.myVaultToken';
    vVault.MountPath := 'transit';
    vVault.KeyName := 'my-signing-key';
    vVault.Connect;
    vVault.SetCertificateFromFile('C:\certs\signing-cert.pem');
    // vSigner.KeyProvider := vVault;
  finally
    vVault.Free;
  end;
end;

TsgcCertumSimplySignProvider

Certum SimplySign. Polish QTSP. Qualified electronic signatures via mobile-app-authorised PIN, no USB token required. Common choice for Polish KSeF and ZUS workflows.

  • OAuth2 client credentials + SimplySign account username/password + PIN.
  • ListCertificates exposes every cert available in the account.
certum.pas
var
  vCertum: TsgcCertumSimplySignProvider;
begin
  vCertum := TsgcCertumSimplySignProvider.Create(nil);
  try
    vCertum.ClientId := 'your-client-id';
    vCertum.ClientSecret := 'your-client-secret';
    vCertum.Username := 'user@example.com';
    vCertum.Password := 'account-password';
    vCertum.PIN := '123456';
    vCertum.BaseURL := 'https://cloudsign.certum.pl';
    vCertum.Connect;
    // vSigner.KeyProvider := vCertum;
  finally
    vCertum.Free;
  end;
end;

TsgcCSCKeyProvider

Cloud Signature Consortium API v2. Generic interface to any QTSP that implements CSC v2 — Universign, D-Trust sign-me, A-Trust, FNMT Cl@ve Firma, Evrotrust, Intesi Group. The provider holds the qualified key in a remote QSCD; sgcSign sends only the document hash.

  • Three auth modes: cscBasic, cscOAuth2, cscOTP (one-time password for two-factor).
  • Calls credentials/authorize + signatures/signHash per CSC v2 spec.
csc-v2.pas
var
  vCSC: TsgcCSCKeyProvider;
  vCreds: TStringArray;
begin
  vCSC := TsgcCSCKeyProvider.Create(nil);
  try
    vCSC.BaseURL := 'https://api.qtsp.example/csc/v2';
    vCSC.AuthMethod := cscBasic;
    vCSC.Username := 'alice';
    vCSC.Password := 'secret';
    vCreds := vCSC.ListCredentials;
    vCSC.CredentialID := vCreds[0];
    vCSC.PIN := '123456';
    vCSC.OTP := '987654';
    vCSC.LoadCredentialInfo;
    // vSigner.KeyProvider := vCSC;
  finally
    vCSC.Free;
  end;
end;

Swap with One Line

Every provider implements IsgcKeyProvider. The signer code never knows whether the key lives on disk, on a token, in Azure, or behind a CSC v2 API.

One signer, ten providers

  • Develop with a local PFX. Test with the Windows store. Deploy to Azure Trusted Signing.
  • Country profiles, signature levels, OCSP, timestamps — everything else stays the same.
  • The sgcSign Server uses the same providers internally — centralise locally first, scale to a daemon later.
swap-providers.pas
function SignWithAnyProvider(
  aProvider: IsgcKeyProvider; const aXML: string): string;
var
  vSigner: TsgcXAdESSigner;
begin
  vSigner := TsgcXAdESSigner.Create(nil);
  try
    vSigner.KeyProvider := aProvider;
    vSigner.Profile.LoadProfile(spEmploymentDE);
    Result := vSigner.SignXML(aXML);
  finally
    vSigner.Free;
  end;
end;

// Caller picks the provider; signer doesn't care.
SignWithAnyProvider(vPFX, vXML);
SignWithAnyProvider(vAzure, vXML);
SignWithAnyProvider(vCSC, vXML);

Pick the Right Provider for Your Trust Model

From a local .pfx to an HSM in another continent — the signing code stays the same.