Skip to content

Instantly share code, notes, and snippets.

View iamxiyang's full-sized avatar
😀

何喜阳 iamxiyang

😀
View GitHub Profile
@iamxiyang
iamxiyang / uniapp-arraybuffer-sha256.ts
Created December 11, 2022 03:46
uniapp 读取文件 ArrayBuffer 获取 SHA 值,兼容 H5、小程序、APP
import { lib as CryptoLib, SHA256 } from 'crypto-js'
const arrayBufferToWordArray = (ab: any) => {
const i8a = new Uint8Array(ab)
const a = []
for (let i = 0; i < i8a.length; i += 4) {
a.push((i8a[i] << 24) | (i8a[i + 1] << 16) | (i8a[i + 2] << 8) | i8a[i + 3])
}
return CryptoLib.WordArray.create(a, i8a.length)
}