We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
仅使用 std,供参考。要点是模仿 CryptoJS 使用字符串类型 key(实际作为 password 来使用)时,使用 EvpKDF 来生成 key 和 IV。
std
CryptoJS
import {crypto, toHashString} from 'https://deno.land/std@0.200.0/crypto/mod.ts' import {decode } from 'https://deno.land/std@0.200.0/encoding/base64.ts' const evpkdf = async ( password: Uint8Array, salt: Uint8Array, iterations: number, ): Promise<{ key: Uint8Array, iv: Uint8Array, }> => { const keySize = 32 const ivSize = 16 const derivedKey = new Uint8Array(keySize + ivSize) let currentBlock = 1 let digest = new Uint8Array(0) const hashLength = 16 while ((currentBlock - 1) * hashLength < keySize + ivSize) { const data = new Uint8Array(digest.length + password.length + salt.length) data.set(digest) data.set(password, digest.length) data.set(salt, digest.length + password.length) digest = await crypto.subtle.digest('MD5', data).then(buf => new Uint8Array(buf)) for (let i = 1; i < iterations; i++) { digest = await crypto.subtle.digest('MD5', digest).then(buf => new Uint8Array(buf)) } derivedKey.set(digest, (currentBlock - 1) * hashLength) currentBlock++ } return { key: derivedKey.slice(0, keySize), iv: derivedKey.slice(keySize), } } const main = async (env: Record<string, string>) => { const { COOKIE_CLOUD_HOST: CC_HOST, COOKIE_CLOUD_UUID: CC_UUID, COOKIE_CLOUD_PASSWORD: CC_PW, } = env const resp = await fetch(`${CC_HOST}/get/${CC_UUID}`).then(r => r.json()) console.log(resp) let cookies = [] if (resp && resp.encrypted) { console.log(resp.encrypted) console.log(new TextDecoder().decode(decode(resp.encrypted)).slice(0, 16)) const decoded = decode(resp.encrypted) // Salted__ + 8 bytes salt, followed by cipher text const salt = decoded.slice(8, 16) const cipher_text = decoded.slice(16) const password = await crypto.subtle.digest( 'MD5', new TextEncoder().encode(`${CC_UUID}-${CC_PW}`), ).then( buf => toHashString(buf).substring(0, 16) ).then( p => new TextEncoder().encode(p) ) const {key, iv} = await evpkdf(password, salt, 1) const privete_key = await crypto.subtle.importKey( 'raw', key, 'AES-CBC', false, ['decrypt'], ) const d = await crypto.subtle.decrypt( {name: 'AES-CBC', iv}, privete_key, cipher_text, ) console.log('decrypted:', new TextDecoder().decode(d)) }
The text was updated successfully, but these errors were encountered:
感谢,已经添加到仓库首页 https://github.com/easychen/CookieCloud/blob/master/README.md#deno-%E5%8F%82%E8%80%83
Sorry, something went wrong.
好像最后少了一个花括号。
No branches or pull requests
仅使用
std
,供参考。要点是模仿CryptoJS
使用字符串类型 key(实际作为 password 来使用)时,使用 EvpKDF 来生成 key 和 IV。The text was updated successfully, but these errors were encountered: