Skip to content

Instantly share code, notes, and snippets.

View iamnivekx's full-sized avatar
:octocat:
Focusing

Nivek Huang iamnivekx

:octocat:
Focusing
  • shanghai
  • 18:51 (UTC +08:00)
View GitHub Profile
@iamnivekx
iamnivekx / encrypt.ts
Last active April 24, 2024 02:08
encrypt and decrypt the text using the password.
/**
* This file is used to encrypt and decrypt the text using the password.
* The password is used to derive the key using PBKDF2.
* The key is used to encrypt and decrypt the text using AES-GCM.
* The salt is used to derive the key using PBKDF2.
* The nonce is used to encrypt and decrypt the text using AES-GCM.
* The ciphertext is the encrypted text.
* The salt, nonce, and ciphertext are concatenated and converted to Base64.
* inspire by https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/user-storage/encryption.ts
*/