The crypto library that uses WebCryptoApi for Edge Runtime
npm install next-edge-cryptonext-edge-crypto is a JavaScript library crafted to provide sophisticated encryption and decryption functionalities using the WebCrypto API. This library is specially designed for edge runtime environments, such as those in Next.js or Vercel, serving as a contemporary alternative to Node.js's native crypto module.
- WebCrypto API Utilization: Employs the WebCrypto API for encryption and decryption, aligning with contemporary web standards.
- Edge Runtime Optimization: Tailored for peak performance in edge runtime environments.
- Scalable Architecture: Built with a vision to incorporate additional encryption algorithms and broaden functionalities in future updates.
To integrate next-edge-crypto into your project, use the following command:
``bash`
npm install next-edge-cryptoor
yarn add next-edge-crypto
To use the library, start by importing the necessary functions:
`ts`
import { encrypt, decrypt } from 'next-edge-crypto';`
or you can import like this:ts`
import * as crypto from 'next-edge-crypto';
Then, you can use the functions as follows:
`ts`
const encryptedData = await encrypt("your data here", "your base64 encoded key");
console.log(encryptedData); // Outputs encrypted data in hex format
`ts
const decryptedData = await decrypt("your encrypted data here", "your base64 encoded key");
console.log(decryptedData); // Outputs the original data
`
: Encrypts the input string using the AES-CBC algorithm and returns the encrypted data in hex format.
- decrypt(data: string, key: string): Promise