@exodus/crypto
可再使用的加密原始文件,用于浏览器/Node.js/Electron/React Industrial
对于平台未执行的散列,需要 @noble/hashes 依赖性
关于反应原住民的注释
-
在原始反应中, 使用随机性的方法预期
globalThis.crypto.getRandomValues工作的时候. 这可以多填充require('react-native-get-random-values')。 。 。 . -
Buffer应进行多填充(全球或通过捆绑).
常规 API
randomBytes(size)
import { randomBytes } from '@exodus/crypto/randomBytes'
回返a Buffer 长度实例 size 从CSPRNG中填入.
在非节点.js环境中,需要多填充 Buffer。 。 。 .
randomUUID()
import { randomUUID } from '@exodus/crypto/randomUUID'
返回由 CSPRNG 填充的随机UUID(版本4,变体1).
这包含了122位随机性.
兼容 Crypto.randomUID () (中文(简体) )。 。 。 .
await hash(type, arg[, form])
import { hash } from '@exodus/crypto/hash'
哈谢斯 arg 使用指定的散列 type。 。 。 .
返回编码为 form (例如:. 'hex'或作为 Buffer 实例 form 未指定.
例如:
> await hash('sha256', 'abc', 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
> await hash('sha256', Buffer.from('abc'), 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
> await hash('sha256', new Uint8Array([97, 98, 99]), 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
await hash('sha256', Buffer.from('abc'))
Buffer(32) [186, 120, 22, 191, 143, 1, 207, 234, 65, 65, 64, 222, 93, 174, 34, 35, 176, 3, 97, 163, 150, 23, 122, 156, 180, 16, 255, 97, 242, 0, 21, 173]
await hmac(type, secret, arg[, form])
import { hmac } from '@exodus/crypto/hmac'
HMAC的执行,使用类似于 hash()。 。 。 .
空 secret 不支持数值.