更新记录
1.0.0(2026-07-24)
1.0.0
平台兼容性
uni-app x(4.0)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| √ | √ | 5.0 | √ | √ | - |
fadp-crypto 自实现跨平台加密插件
简介
fadp-crypto 加密插件。
核心优势:各平台使用内置加密库,零第三方 Maven/Gradle 依赖。
各平台实现方案
| 平台 | 哈希实现 | AES 实现 | 依赖 |
|---|---|---|---|
| Android | java.security.MessageDigest(JDK 内置) |
javax.crypto.Cipher(JDK 内置) |
零依赖 ✅ |
| iOS | CommonCrypto CC_MD5/CC_SHA*(系统内置) |
CommonCrypto CCCrypt(系统内置) |
零依赖 ✅ |
| 鸿蒙 | @ohos/crypto-js(官方鸿蒙库) |
@ohos/crypto-js |
@ohos/crypto-js |
| Web | crypto-js(npm) |
crypto-js(npm) |
crypto-js |
支持的功能
| 功能 | Android | iOS | 鸿蒙 | Web |
|---|---|---|---|---|
| MD5 | ✅ | ✅ | ✅ | ✅ |
| SHA1 | ✅ | ✅ | ✅ | ✅ |
| SHA256 | ✅ | ✅ | ✅ | ✅ |
| SHA512 | ✅ | ✅ | ✅ | ✅ |
| AES-CBC | ✅ | ✅ | ✅ | ✅ |
| AES-ECB | ✅ | ✅ | ✅ | ✅ |
| AES-CFB | ✅ | ⚠️ | ✅ | ✅ |
| PKCS7 填充 | ✅ | ✅ | ✅ | ✅ |
| SHA3 | ❌ | ❌ | ✅ | ✅ |
| RIPEMD160 | ❌ | ❌ | ✅ | ✅ |
使用方法
直接替换导入路径即可:
import { useCrypto } from '@/uni_modules/fadp-crypto'
const crypto = useCrypto()
// MD5
const md5Result = crypto.MD5('hello world')
// SHA256
const sha256Result = crypto.SHA256('hello world')
// AES 加密(默认 CBC 模式,PKCS7 填充)
const encrypted = crypto.AES.encrypt('需要加密的内容', '1234567890123456')
const decrypted = crypto.AES.decrypt(encrypted, '1234567890123456')
// AES ECB 模式
const encryptedECB = crypto.AES.encrypt('内容', 'key', {
mode: crypto.mode.ECB
})
// 自定义 IV
const encryptedWithIV = crypto.AES.encrypt('内容', 'key', {
mode: crypto.mode.CBC,
iv: 'my_iv_1234567890'
})
// 错误处理
crypto.onError((err) => {
console.error('加密错误:', err)
})
文件结构
uni_modules/fadp-crypto/
├── package.json
├── common/
│ ├── constant.uts # 模式和填充常量
│ └── utils.uts # 工具函数(密钥处理等)
└── utssdk/
├── interface.uts # 接口定义
├── app-android/
│ ├── config.json # ← 零依赖配置
│ ├── AES.uts # javax.crypto AES
│ ├── crypto.uts # MessageDigest 哈希
│ ├── utils.uts # 字节工具
│ ├── utils/index.uts
│ └── index.uts
├── app-ios/
│ ├── FadpCryptoHelper.swift # CommonCrypto 封装
│ ├── AES.uts # 调用 Swift 辅助类
│ ├── crypto.uts
│ └── index.uts
├── app-harmony/
│ ├── config.json # @ohos/crypto-js 依赖
│ ├── AES.ets
│ ├── crypto.ets
│ └── index.uts
└── web/
├── package.json # crypto-js 依赖
├── AES.uts
├── crypto.uts
└── index.uts

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 0
赞赏 0
下载 12454432
赞赏 1935
赞赏
京公网安备:11010802035340号