@iap Packages
    Preparing search index...

    Module @iap/encryptor

    @iap/encryptor

    企业级加密工具库,提供 AES、RSA、MD5、SHA256 加解密能力。所有密钥均由外部调用方传入,库内无任何硬编码默认值。

    • AES(CBC / PKCS7):对称加解密,密钥与 IV 由调用方提供
    • RSA:公钥加密 / 私钥解密,基于 jsencrypt
    • MD5:32 位大写十六进制摘要
    • SHA256:64 位小写十六进制摘要
    • 密钥生成:随机 AES 密钥与 IV 生成工具
    • 所有密钥由调用方传入,库内无硬编码密钥
    • 完整 TypeScript 类型支持,支持 tree-shaking 的 ESM + CJS 双格式输出
    pnpm add @iap/encryptor
    
    import { aesEncrypt, aesDecrypt, aesGenerateKey, aesGenerateIV } from '@iap/encryptor'

    const key = aesGenerateKey(16) // 随机 128 位密钥
    const iv = aesGenerateIV(16) // 随机 IV

    const cipher = aesEncrypt('hello world', { key, iv })
    const plain = aesDecrypt(cipher, { key, iv }) // 'hello world'
    import { aesEncrypt, aesDecrypt, aesGenerateKey, aesGenerateIV } from '@iap/encryptor'
    
    函数 说明
    aesEncrypt(plaintext, { key, iv }) AES-CBC + PKCS7 加密,返回 Base64 字符串
    aesDecrypt(ciphertext, { key, iv }) AES-CBC + PKCS7 解密,返回原始字符串
    aesGenerateKey(length) 生成随机密钥字符串(通常 16 或 32 位)
    aesGenerateIV(length) 生成随机 IV 字符串(通常 16 位)
    import { rsaEncrypt, rsaDecrypt } from '@iap/encryptor'
    
    函数 说明
    rsaEncrypt(data, publicKeyPem) 使用 RSA 公钥加密(PEM 格式)
    rsaDecrypt(ciphertext, privateKeyPem) 使用 RSA 私钥解密(PEM 格式)

    加解密失败时均会抛出 Error。

    import { md5Hash } from '@iap/encryptor'

    md5Hash('hello') // '5D41402ABC4B2A76B9719D911017C592'
    import { sha256Hash } from '@iap/encryptor'

    sha256Hash('hello') // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
    sha256Hash('') // ''
    import type { AESEncryptOptions, EncryptorConfig } from '@iap/encryptor'
    
    AESEncryptOptions
    EncryptorConfig
    LoggerAdapter
    aesDecrypt
    aesEncrypt
    aesGenerateIV
    aesGenerateKey
    configure
    md5Hash
    rsaDecrypt
    rsaEncrypt
    sha256Hash