Skip to content

Instantly share code, notes, and snippets.

View ChaoLiangSuper's full-sized avatar

Chao Liang ChaoLiangSuper

  • Melbourne
View GitHub Profile
@ChaoLiangSuper
ChaoLiangSuper / encryption.ts
Last active March 24, 2024 14:30 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in typescript
import crypto from 'crypto';
const ALGORITHM = 'aes-256-cbc';
const ENCODING = 'hex';
const IV_LENGTH = 16;
const KEY = process.env.ENCRYPTION_KEY!;
export const encrypt = (data: string) => {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(ALGORITHM, new Buffer(KEY), iv);
@ChaoLiangSuper
ChaoLiangSuper / token-generator.js
Created May 10, 2019 15:09 — forked from ziluvatar/token-generator.js
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');