Download 6.0.0-dev.6/browserstate/crypto.ts from gradio/frontend: direct link, hf CLI and curl.
- Browser
- Download file 886 Bytes
-
https://huggingface.co/datasets/gradio/frontend/resolve/834fa270e16a74074f07cfdd678317d826c68dd3/6.0.0-dev.6/browserstate/crypto.ts
- Command line
-
hf download hf://datasets/gradio/frontend@834fa270e16a74074f07cfdd678317d826c68dd3/6.0.0-dev.6/browserstate/crypto.ts
-
curl -L -o crypto.ts https://huggingface.co/datasets/gradio/frontend/resolve/834fa270e16a74074f07cfdd678317d826c68dd3/6.0.0-dev.6/browserstate/crypto.ts
886 Bytes
| import CryptoJS from "crypto-js"; | |
| export function encrypt(data: string, key: string): string { | |
| const hashedKey = CryptoJS.SHA256(key).toString(); | |
| const iv = CryptoJS.lib.WordArray.random(16); | |
| const encrypted = CryptoJS.AES.encrypt(data, hashedKey, { | |
| iv: iv, | |
| mode: CryptoJS.mode.CBC, | |
| padding: CryptoJS.pad.Pkcs7 | |
| }); | |
| const ivString = CryptoJS.enc.Base64.stringify(iv); | |
| const cipherString = encrypted.toString(); | |
| return ivString + ":" + cipherString; | |
| } | |
| export function decrypt(encryptedData: string, key: string): string { | |
| const hashedKey = CryptoJS.SHA256(key).toString(); | |
| const [ivString, cipherString] = encryptedData.split(":"); | |
| const iv = CryptoJS.enc.Base64.parse(ivString); | |
| const decrypted = CryptoJS.AES.decrypt(cipherString, hashedKey, { | |
| iv: iv, | |
| mode: CryptoJS.mode.CBC, | |
| padding: CryptoJS.pad.Pkcs7 | |
| }); | |
| return decrypted.toString(CryptoJS.enc.Utf8); | |
| } | |