FAQ-000704 - Data Storage and Encryption Security / Encryption and Key Management

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
How can I securely store encryption keys in post-install scripts when custom settings and metadata are not accessible?
Answer
To securely store encryption keys in post-install scripts when custom settings and metadata are not accessible in Salesforce, you can follow these steps: 1. **Use a Custom Object**: Store the encryption key in a custom object, ensuring the field is encrypted using AES symmetric encryption/decryption in Apex. 2. **Secure the Encryption Key**: Store the key used for encrypting the custom object field in a protected custom metadata or protected custom setting. This ensures the key itself is securely stored and not directly accessible. 3. **Implement Access Controls**: Restrict access so that only authorized users or processes can access the decrypted value of the encryption key. 4. **Limit Exposure**: Avoid declaring the post-install script as global. Use a public declaration instead to reduce security risks. This approach aligns with Salesforce's security best practices for securely managing encryption keys.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexBadCryptoAvoidHardcodedCredentialsInFieldDeclsAvoidHardcodedCredentialsInVarAssignAvoidHardcodedCredentialsInVarDeclsAvoidGlobalInstallUninstallHandlersApexSuggestUsingNamedCred
Question
How can I securely store encryption keys in post-install scripts when custom settings and metadata are not accessible?
Recommended Answer Update
To securely store encryption keys in post-install scripts when custom settings and metadata are not accessible in Salesforce, you can follow these steps: 1. **Use a Custom Object**: Store the encryption key in a custom object, ensuring the field is encrypted using platform encryption or AES symmetric encryption/decryption in Apex. 2. **Secure the Encryption Key**: Store the key used for encrypting the custom object field in a protected custom metadata or protected custom setting. This ensures the key itself is securely stored and not directly accessible. 3. **Implement Access Controls**: Restrict access so that only authorized users or processes can access the decrypted value of the encryption key. 4. **Limit Exposure**: Avoid declaring the post-install script as global. Use a public declaration instead to reduce security risks. This approach aligns with Salesforce's security best practices for securely managing encryption keys.
Reasoning
The answer needed minor refinement to improve clarity around encryption methods. I changed 'AES symmetric encryption/decryption in Apex' to 'platform encryption or AES symmetric encryption/decryption in Apex' to acknowledge both Salesforce's built-in platform encryption and custom encryption approaches. This provides a more complete picture of available secure storage options. Regarding the selected security rules: 1. **ApexBadCrypto**: This rule relates directly to the FAQ's discussion of 'AES symmetric encryption/decryption in Apex' - it helps detect weak cryptographic implementations in Apex code. 2. **AvoidHardcodedCredentialsInFieldDecls**, **AvoidHardcodedCredentialsInVarAssign**, **AvoidHardcodedCredentialsInVarDecls**: These three rules are highly relevant to the FAQ's core concern about securely storing encryption keys. The FAQ specifically addresses how to avoid hardcoding encryption keys by using custom objects and protected custom metadata/settings. 3. **AvoidGlobalInstallUninstallHandlers**: This rule directly corresponds to the FAQ's point #4 about 'Avoid declaring the post-install script as global. Use a public declaration instead to reduce security risks.' 4. **ApexSuggestUsingNamedCred**: While the FAQ focuses on encryption keys, this rule is relevant to the broader context of secure credential management in post-install scripts, which aligns with the FAQ's security-focused approach to credential storage.
Reasoning References