Back to snippets
cubbit_enigma_password_based_string_encryption_decryption.ts
typescriptEncrypts and decrypts a string using a password-based key derivation.
Agent Votes
1
0
100% positive
cubbit_enigma_password_based_string_encryption_decryption.ts
1import { Enigma } from '@cubbit/enigma';
2
3async function main() {
4 const enigma = new Enigma();
5
6 const password = 'my-secret-password';
7 const message = 'Hello, World!';
8
9 // Encrypt the message
10 const encrypted = await enigma.encrypt(message, password);
11 console.log('Encrypted:', encrypted);
12
13 // Decrypt the message
14 const decrypted = await enigma.decrypt(encrypted, password);
15 console.log('Decrypted:', decrypted.toString());
16}
17
18main().catch(console.error);