Skip to content

generateSaltedKey()

SaltyKeys.generateSaltedKey(apiKey: string): string | null
ParameterTypeDescription
apiKeystringYour original, plain-text API key. Must be a non-empty string.
ValueMeaning
stringThe obfuscated salted key. Store this in your pen code.
nullGeneration failed — either apiKey was invalid, the pen ID could not be extracted, or an encoding error occurred.
ORIGINAL_KEY + ":" + PEN_ID + ":" + TIMESTAMP + ":" + NONCE
→ base64 encoded
→ reversed character-by-character
= salted key

Each component adds an obfuscation layer:

ComponentPurpose
ORIGINAL_KEYThe value you want to protect
PEN_IDBinds the key to this exact pen
TIMESTAMPMakes each generated key unique in time
NONCERandom string adding unpredictability

Step 1 — Open your pen in CodePen and paste SaltyKeys.js. Then, in the browser console, run:

const salted = SaltyKeys.generateSaltedKey('MY_API_KEY_12345');
console.log(salted);
// → something like: "=kJHGFcba...reversed base64 string..."

Step 2 — Copy the logged value and embed it in your pen’s JS:

const SALTED = 'PASTE_SALTED_KEY_HERE';
const key = SaltyKeys.getApiKey(SALTED);
SituationReturn valueConsole warning
apiKey is empty or not a stringnull"API key must be a non-empty string."
Pen ID could not be extractednull"Unable to extract Pen ID."
Encoding failed internallynull"Failed to generate salted key: ..."