当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
16 Star 47 Fork 40

OpenHarmony-SIG/ohos_crypto_js
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

crypto-js

简介

本软件是移植开源软件 crypto-js 源码在OpenHarmony上进行功能适配,在OpenHarmony上已支持原库crypto-js的功能,目前crypto-js已支持的算法有:MD5、SHA-1、SHA-256、HMAC、HMAC-MD5、HMAC-SHA1、HMAC-SHA256、PBKDF2、AES、RC4、DES等。

preview.gif

下载安装

ohpm  install @ohos/crypto-js 

OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm 包

使用说明

  1. 引入依赖
最新版本支持
  import { CryptoJS } from '@ohos/crypto-js' 或者
  import CryptoJS from '@ohos/crypto-js'
  1. md5算法使用

    md5信息摘要算法(英语:md5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用于确保信息传输完整一致。

    md5特点:

    1. 不可逆性 --- 根据 MD5 值计算不出原始数据
    2. 唯一性 --- 不同原始数据会有不同的 MD5 值

    md5算法在本库的使用:

  //第一步在需要使用到的页面,导入CryptoJS
  import { CryptoJS } from '@ohos/crypto-js'
  //第二步在需要使用到md5的业务逻辑,调用md5算法
  var hash = CryptoJS.MD5("123456") //传参是需要加密的内容,返回值是加密后的数据
  1. aes算法使用

    AES算法全称Advanced Encryption Standard,又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。

    AES是对称加密,所以加密解密都需要用到同一个秘钥。

    AES算法在本库的使用:

   //第一步在需要使用到的页面,导入CryptoJS
  import { CryptoJS } from '@ohos/crypto-js'
  //第二步定义加密解密需要用到的key
  var key = 'secret key 1234'
  //第三步在需要使用AES加密的业务逻辑,调用AES加密
  var encrypted = CryptoJS.AES.encrypt('hello world', key).toString()  //传参为加密内容及秘钥
  //第四步在需要把上面的加密块解密的业务逻辑,调用AES解密,注意key必须相同
  var decrypted = CryptoJS.AES.decrypt(encrypted, key) //传参为加密后的内容及秘钥

其它加密算法使用方式,如sha1、sha256、sha224、sha512、sha384、sha3、ripemd160、hmac-md5、hmac-sha1、hmac-sha256、hmac-sha224、hmac-sha512、hmac-sha384、hmac-sha3、hmac-ripemd160 、pbkdf2、aes、tripledes、rc4、rabbit、rabbit-legacy、evpkdf、des、triple-des、format-openssl、format-hex、enc-latin1、enc-utf8、enc-hex、enc-utf16、enc-base64、 mode-cfb、mode-ctr、mode-ctr-gladman、mode-ofb、mode-ecb、pad-pkcs7、pad-ansix923、pad-iso10126、pad-iso97971、pad-zeropadding、pad-nopadding。

更多使用方法请参照 demoXTS参考原库使用文档

接口列表

  • crypto-js/md5
  • crypto-js/sha1
  • crypto-js/sha256
  • crypto-js/sha224
  • crypto-js/sha512
  • crypto-js/sha384
  • crypto-js/sha3
  • crypto-js/ripemd160

  • crypto-js/hmac-md5
  • crypto-js/hmac-sha1
  • crypto-js/hmac-sha256
  • crypto-js/hmac-sha224
  • crypto-js/hmac-sha512
  • crypto-js/hmac-sha384
  • crypto-js/hmac-sha3
  • crypto-js/hmac-ripemd160

  • crypto-js/pbkdf2

  • crypto-js/aes
  • crypto-js/tripledes
  • crypto-js/rc4
  • crypto-js/rabbit
  • crypto-js/rabbit-legacy
  • crypto-js/evpkdf
  • crypto-js/des
  • crypto-js/triple-des

  • crypto-js/format-openssl
  • crypto-js/format-hex

  • crypto-js/enc-latin1
  • crypto-js/enc-utf8
  • crypto-js/enc-hex
  • crypto-js/enc-utf16
  • crypto-js/enc-base64

  • crypto-js/mode-cfb
  • crypto-js/mode-ctr
  • crypto-js/mode-ctr-gladman
  • crypto-js/mode-ofb
  • crypto-js/mode-ecb

  • crypto-js/pad-pkcs7
  • crypto-js/pad-ansix923
  • crypto-js/pad-iso10126
  • crypto-js/pad-iso97971
  • crypto-js/pad-zeropadding
  • crypto-js/pad-nopadding

约束与限制

在下述版本验证通过:

  • DevEco Studio: NEXT Beta1-5.0.3.806, SDK:API12 Release(5.0.0.66)
  • DevEco Studio : 5.0.3.122, SDK: API12 (5.0.0.17)
  • DevEco Studio : 4.1.3.600, SDK: API11 (4.1.0.67)

目录结构

|---- crypto-js  
|     |---- entry  # 示例代码文件夹
|     |---- crypto  # crypto-js库文件夹
|         |---- index.ts  # 对外接口
|         |---- src
|             |---- main
|                 |---- ets
|                     |---- components
|                         |---- crypto.ts  # 加密封装类
|     |---- README.md  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue ,当然,也非常欢迎发 PR 共建。

开源协议

本项目基于 MIT License ,请自由地享受和参与开源。

遗留问题

  • pbkdf2算法性能问题
# License [The MIT License (MIT)](http://opensource.org/licenses/MIT) Copyright (c) 2009-2013 Jeff Mott Copyright (c) 2013-2016 Evan Vosberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

本软件是移植开源软件 crypto-js 源码在OpenHarmony上进行功能适配,在OpenHarmony上已支持原库crypto-js的功能 展开 收起
JavaScript 等 4 种语言
MIT
取消

发行版 (11)

全部
6个月前

ohos_crypto_js 开源评估指数

productivity 生产力
niche_creation 创新力
robustness 稳健性
collaboration 协作
contributor 贡献者
software 软件

近期动态

2个月前创建了任务 #IBHVUC 是否支持 useNormalizedOHMUrl": true
2个月前被 朱程程 移出了仓库
2个月前将 andyhm10000 移出了仓库
2个月前被 朱程程 移出了仓库
2个月前将 chenwenjiehw 移出了仓库
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-sig/ohos_crypto_js.git
git@gitee.com:openharmony-sig/ohos_crypto_js.git
openharmony-sig
ohos_crypto_js
ohos_crypto_js
master

搜索帮助