1. Import the `decrypt` function provided in `/decrypt.js`:
```javascript
-import decrypt from 'https://cdn.jsdelivr.net/gh/ardislu/static-encrypt/decrypt.js';
+import { decrypt } from 'https://cdn.jsdelivr.net/gh/ardislu/static-encrypt/decrypt.js';
```
2. Pass the encrypted content string and the password to the `decrypt` function:
You can also import the function dynamically (useful for lazy-loading or testing in DevTools):
```javascript
-const { default: decrypt } = await import('https://cdn.jsdelivr.net/gh/ardislu/static-encrypt/decrypt.js');
+const { decrypt } = await import('https://cdn.jsdelivr.net/gh/ardislu/static-encrypt/decrypt.js');
```
* @param {string} password - The password used to encrypt the string.
* @returns {Promise<string>} A promise that resolves to the plaintext.
*/
-export default async function decrypt(content, password) {
+export async function decrypt(content, password) {
const encoder = new TextEncoder();
const encodedPassword = encoder.encode(password);
const additionalData = encoder.encode('https://github.com/ardislu/static-encrypt');
* @param {string} password - The password used to encrypt the string.
* @returns {Promise<string>} A promise that resolves to the ciphertext.
*/
-export default async function encrypt(plaintext, password) {
+export async function encrypt(plaintext, password) {
const encoder = new TextEncoder();
const encodedPlaintext = encoder.encode(plaintext);
const encodedPassword = encoder.encode(password);
</footer>
<script type="module">
- import encrypt from '/encrypt.js';
- import decrypt from '/decrypt.js';
+ import { encrypt } from '/encrypt.js';
+ import { decrypt } from '/decrypt.js';
function setOutput(ciphertext) {
document.querySelector('#output').style.display = 'block';