Interactive Demo
Demo 1 — Generate and decode a key
Section titled “Demo 1 — Generate and decode a key”This pen demonstrates the full workflow: configure SaltyKeys, generate a salted key in the console, then decode it.
Demo 2 — Context validation
Section titled “Demo 2 — Context validation”This pen generates a salted key, then shows that changing the simulated pen ID causes getApiKey() to return null.
Demo 3 — Custom URL pattern
Section titled “Demo 3 — Custom URL pattern”Configure SaltyKeys for a non-CodePen environment using a custom URL pattern.
Running demos locally
Section titled “Running demos locally”If you want to test SaltyKeys.js without CodePen:
- Open any webpage in your browser
- Open Developer Tools → Console
- Paste the contents of
SaltyKeys.js - Override
getPenIdto return a fixed string:SaltyKeys.getPenId = () => 'test-id';const salted = SaltyKeys.generateSaltedKey('my-key');console.log(SaltyKeys.getApiKey(salted)); // → 'my-key'
SaltyKeys.js uses browser globals (window, document, btoa). To test in Node.js, polyfill them:
global.window = { location: { href: 'https://codepen.io/user/pen/AbCdEf' } };global.document = { querySelector: () => null };global.btoa = (s) => Buffer.from(s, 'binary').toString('base64');global.atob = (s) => Buffer.from(s, 'base64').toString('binary');
// Then load SaltyKeyseval(require('fs').readFileSync('SaltyKeys.js', 'utf8'));
console.log(SaltyKeys.getPenId()); // → 'AbCdEf'