【问题标题】:CryptoJS Progressive CipheringCryptoJS 渐进式加密
【发布时间】:2022-10-14 08:15:21
【问题描述】:

有没有其他关于如何使用 CryptoJS 进行渐进式加密的教程或文档? 他们自己的关于它的文档有点缺乏信息

这些是我找到的信息:

https://cryptojs.gitbook.io/docs/#progressive-ciphering https://github.com/brix/crypto-js/blob/develop/docs/QuickStartGuide.wiki

【问题讨论】:

  • 你有什么问题?

标签: cryptojs


【解决方案1】:

这是我的解决方案:

export function calcSha1 (file: File): Promise<string> {
  const reader = new FileReader()
  const promise = new Promise<string>(
    (resolve) => {
      reader.onloadend = (evt: ProgressEvent<FileReader>) => {
        const sha1Hash = CryptoJS.algo.SHA1.create()
        let currentPosition = 0
        const chunkSize = 10 * 1024 * 1024 // 10MB
        while (currentPosition < file.size) {
          let endPosition = currentPosition + chunkSize
          if (endPosition > file.size) {
            endPosition = file.size
          }
          const blob = evt.target?.result?.slice(currentPosition, endPosition)
          const wordArray = CryptoJS.lib.WordArray.create(blob)
          sha1Hash.update(wordArray)
          currentPosition += chunkSize
        }
        const result = sha1Hash.finalize()
        resolve(result.toString())
      }
    }
  )
  reader.readAsArrayBuffer(file)
  return promise
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多