Download api/src/misc/crypto.js from Dieiol919/cobalt: direct link, hf CLI and curl.
- Browser
- Download file 708 Bytes
-
https://huggingface.co/Dieiol919/cobalt/resolve/main/api/src/misc/crypto.js
- Command line
-
hf download hf://Dieiol919/cobalt/api/src/misc/crypto.js
-
curl -L -o crypto.js https://huggingface.co/Dieiol919/cobalt/resolve/main/api/src/misc/crypto.js
708 Bytes
| import { createCipheriv, createDecipheriv } from "crypto"; | |
| const algorithm = "aes256"; | |
| export function encryptStream(plaintext, iv, secret) { | |
| const buff = Buffer.from(JSON.stringify(plaintext)); | |
| const key = Buffer.from(secret, "base64url"); | |
| const cipher = createCipheriv(algorithm, key, Buffer.from(iv, "base64url")); | |
| return Buffer.concat([ cipher.update(buff), cipher.final() ]) | |
| } | |
| export function decryptStream(ciphertext, iv, secret) { | |
| const buff = Buffer.from(ciphertext); | |
| const key = Buffer.from(secret, "base64url"); | |
| const decipher = createDecipheriv(algorithm, key, Buffer.from(iv, "base64url")); | |
| return Buffer.concat([ decipher.update(buff), decipher.final() ]) | |
| } | |