Skip to content

Instantly share code, notes, and snippets.

View flut1's full-sized avatar

Floris Bernard flut1

  • Amsterdam, Netherlands
View GitHub Profile
@flut1
flut1 / utilTypes.ts
Last active March 7, 2024 11:22
Common TypeScript utility types
/**
* Extracts all keys of object T that have a value assignable to V
*/
type KeysOfType<T, V> = {
[K in keyof T]: T[K] extends V ? K : never
}[keyof T];
namespace KeysOfTypeExample {
type Foo = {
prop1: number,
@flut1
flut1 / unprotectAspNetIdentityCookie.js
Last active April 17, 2024 11:47
Unprotects a cookie in Node.JS that was encrypted using ASP.NET Core Identity with the default settings.
import { padStart } from 'lodash';
import leb128 from 'leb128';
import crypto from 'crypto';
// magic header used to identify an identity cookie
const MAGIC_HEADER = 0x09F0C9F0;
// key id size in bytes
const SIZE_KEY_ID = 16;
// size of key modifier according to the CbcAuthenticatedEncryptor:
// https://github.com/aspnet/DataProtection/blob/dev/src/Microsoft.AspNetCore.DataProtection/Cng/CbcAuthenticatedEncryptor.cs