A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at fix/spotify 28 lines 799 B view raw
1import crypto from "crypto"; 2import { env } from "./env"; 3 4export function encrypt(text: string, key: string) { 5 const iv = Buffer.from(env.SPOTIFY_ENCRYPTION_IV, "hex"); 6 const cipher = crypto.createCipheriv( 7 "aes-256-ctr", 8 Buffer.from(key, "hex"), 9 iv, 10 ); 11 const encrypted = Buffer.concat([ 12 cipher.update(text, "utf8"), 13 cipher.final(), 14 ]); 15 return encrypted.toString("hex"); 16} 17 18export function decrypt(encrypted: string, key: string) { 19 const iv = Buffer.from(env.SPOTIFY_ENCRYPTION_IV, "hex"); 20 const content = Buffer.from(encrypted, "hex"); 21 const decipher = crypto.createDecipheriv( 22 "aes-256-ctr", 23 Buffer.from(key, "hex"), 24 iv, 25 ); 26 const decrypted = Buffer.concat([decipher.update(content), decipher.final()]); 27 return decrypted.toString("utf8"); 28}