A library that implements the Fernet algorithm using the Web Crypto API.
npm install fernet-web``node
npm install fernet-web
`
`typescript`
import Fernet, { InvalidTokenError } from 'fernet';
// Create a new Fernet instance using a secret key
const fernet = await Fernet.create("-lf4DsgLkOaE1GbtIQKNGU1NPQByMDKP2a6Enl9rclE=");
// Encrypt a message
const encryptedToken = await fernet.encrypt("Hello world!");
// Decrypt the encrypted message
const decryptedMessage = await fernet.decrypt(encryptedToken);
// Print the decrypted message
console.log(decryptedMessage); // Hello world!
class is used to create and use Fernet encryption instances.
class with the provided secret key. If secretKey_b64 is null, a new secret key is generated.
#### Parameters:
- secretKey_b64: A base64-encoded string representation of the secret key to use. If null, a new secret key will be generated.
#### Returns:
A promise that resolves with a new Fernet instance.
$3
Encrypt a message into a Fernet token.
#### Parameters
- plainText: The message to encrypt.
#### Returns:
A promise that resolves with a base64-encoded Fernet token.
$3
Decrypt a Fernet token and return the plain text message.
#### Parameters
- token_b64`: A base64-encoded Fernet token.