When storing sensitive data, such as API keys, you must ensure to encrypt your data in Database.
To use these utilities, you must provide an environment variable named SECRET_KEY
. This should be provided safely using your CI since it's a secret key.
MakerKit provides some utilities to encrypt and decrypt your data.
import { encrypt, decrypt } from '~/core/generic/crypto';
// storing secrets
function storeApiKey(key: string) {
const encryptedKey = encrypt(key);
return storeKeyInDb(encryptedKey);
}
// retrieving secrets
function getApiKey(id: string) {
const encryptedKey = await getApiKeyFromDb(id);
return decrypt(encryptedKey);
}