# How does Certificate and Key Management protect cryptographic keys used in secure enterprise integrations?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Certificate Management, Cryptographic Security

Read it on the site: https://www.forcechallenges.com/interview-questions/how-does-certificate-and-key-management-protect-cryptographic-keys-used-in-secure-enterprise-integrations

## Answer

**Basics:** A digital certificate binds a public key to an identity; the matching private key proves you own it. Integrations use them to sign tokens, prove identity to another server, or verify that a payload came from a trusted party. Salesforce provides one place to create, import and rotate them.

**How it works:**
1. Setup > Certificate and Key Management > create a Self-Signed Certificate (choose key size, commonly 2048) or a CA-Signed Certificate (generate a CSR, send to the CA, upload the signed result).
2. Or import a JKS keystore that already holds a key pair.
3. Reference the certificate by its unique name: in a Connected App for JWT bearer flow, in SAML/SSO settings for signing assertions, in a Named Credential/External Credential for client certificate (mutual TLS) authentication, or in Apex via `Crypto.signWithCertificate` and `HttpRequest.setClientCertificateName`.
4. Download only the public certificate to share with partners.

**Advanced / deep dive:** The same Setup area also holds Shield Platform Encryption key management (tenant secrets, bring-your-own-key, cache-only keys), which is a different key class from integration certificates. For inbound mutual authentication, certificates are uploaded as trusted CA/client certificates and must be enabled for the org (some capabilities need Salesforce Support to enable; verify). Self-signed certificates suit internal JWT flows; production partners usually require CA-signed certificates. Plan rotation: certificates expire, and an expired certificate breaks SSO or JWT logins instantly. Sandboxes inherit certificate metadata on refresh but keys differ per org, so do not assume parity.

**Code / config example:**
```apex
// Sign a JWT-style payload with a Salesforce-held private key (key never leaves the platform)
String header  = EncodingUtil.base64Encode(Blob.valueOf('{"alg":"RS256","typ":"JWT"}'));
String payload = EncodingUtil.base64Encode(Blob.valueOf('{"iss":"clientId","aud":"https://login.salesforce.com"}'));
String unsigned = header + '.' + payload;
Blob sig = Crypto.signWithCertificate('RSA-SHA256', Blob.valueOf(unsigned), 'My_Integration_Cert');
String jwt = unsigned + '.' + EncodingUtil.base64Encode(sig);
```
(Production code must base64url-encode, not plain base64.)

**Hidden gotchas & must-remember points:**
- Certificates expire; set calendar reminders and rotate before expiry.
- JWT segments require base64url encoding, a common signing bug.
- Private keys of Salesforce-generated certificates cannot be read by Apex; export of keystores is permitted only for exportable keys.
- Use the certificate API name (unique name), not the label, in code.
- Platform Encryption keys are separate from integration certificates.
- Mutual-TLS client certificates are applied via Named Credentials in modern orgs.

**Best practice:** Use CA-signed certificates for external partners, track expiry dates, and prefer Named/External Credentials over embedding signing logic in Apex.

---
Source: ForceChallenges · last updated 2026-11-02
