Skip to content

Instantly share code, notes, and snippets.

@vruffer
vruffer / base64decode.ts
Created February 3, 2026 10:08
Base64Url decoding in the browser
// From the polyfill of UInt8Array().toHex(), for some reason, you cannot .map a Uint8Array with the same result
// https://github.com/tc39/proposal-arraybuffer-base64/blob/main/playground/polyfill-core.mjs
function uint8ArrayToHex(arr: Uint8Array) {
let out = '';
for (let i = 0; i < arr.length; i += 1) {
out += arr[i]!.toString(16).padStart(2, '0');
}
return out;
}
@vruffer
vruffer / AWS Lambda NextToken Encryption.mjs
Created February 7, 2023 08:33
Code to encrypt a LastEvaluatedKey into a nextToken, which is then decrypted back into an ExclusiveStartKey
import { DecryptCommand, EncryptCommand, KMSClient } from '@aws-sdk/client-kms';
const client = new KMSClient({});
const keyId = 'alias/some-kms-key-id';
const encoder = new TextEncoder();
const decoder = new TextDecoder('utf-8', {
fatal: true,
});