From 6e81254f321d70346991bb8a4f9927c2d1e7b8bd Mon Sep 17 00:00:00 2001 From: hexagon1337 Date: Fri, 20 Sep 2024 14:53:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hexagon1337 --- README.md | 98 +++++------ README_zh.md | 153 ++++++++++++++++++ entry/src/main/ets/pages/Index.ets | 4 +- .../main/resources/base/element/string.json | 4 + .../main/resources/zh_CN/element/string.json | 4 + 5 files changed, 212 insertions(+), 51 deletions(-) create mode 100644 README_zh.md diff --git a/README.md b/README.md index 6250567..e6e6cc2 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,62 @@ # crypto-js -## 简介 - 本软件是移植开源软件 [crypto-js](https://github.com/brix/crypto-js) 源码在OpenHarmony上进行功能适配,在OpenHarmony上已支持原库crypto-js的功能,目前crypto-js已支持的算法有:MD5、SHA-1、SHA-256、HMAC、HMAC-MD5、HMAC-SHA1、HMAC-SHA256、PBKDF2、AES、RC4、DES等。 +## Introduction +This project adapts the open-source [crypto-js](https://github.com/brix/crypto-js) library for OpenHarmony. It supports a range of cryptographic algorithms such as MD5, SHA-1, SHA-256, HMAC, HMAC-MD5, HMAC-SHA1, HMAC-SHA256, PBKDF2, AES, RC4, and DES. ![preview.gif](preview/preview.gif) -## 下载安装 +## How to Install ```shell ohpm install @ohos/crypto-js ``` -OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) -## 使用说明 -1. 引入依赖 +For details about the OpenHarmony ohpm environment configuration, see [OpenHarmony HAR](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.en.md). +## How to Use +1. Import dependencies. ``` -最新版本支持 - import { CryptoJS } from '@ohos/crypto-js' 或者 +Supported by the latest version + import { CryptoJS } from '@ohos/crypto-js' or import CryptoJS from '@ohos/crypto-js' ``` -2. md5算法使用 +2. MD5 usage - md5信息摘要算法(英语:md5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用于确保信息传输完整一致。 + The MD5 message-digest algorithm is a widely used hash function producing a 128-bit (16-byte) hash value to ensure information integrity and consistency during transmission. - md5特点: - 1. 不可逆性 --- 根据 MD5 值计算不出原始数据 - 2. 唯一性 --- 不同原始数据会有不同的 MD5 值 + MD5 features: + 1. Irreversibility: The original data cannot be calculated from the MD5 value. + 2. Uniqueness: Different original data has different MD5 values. - md5算法在本库的使用: + Use of the MD5 algorithm in this library: ``` - //第一步在需要使用到的页面,导入CryptoJS + // Step 1: Import CryptoJS on the page where it is needed. import { CryptoJS } from '@ohos/crypto-js' - //第二步在需要使用到md5的业务逻辑,调用md5算法 - var hash = CryptoJS.MD5("123456") //传参是需要加密的内容,返回值是加密后的数据 + // Step 2: Call the MD5 algorithm in the business logic where it is needed. + var hash = CryptoJS.MD5("123456") // The parameter is the content to be encrypted, and the return value is the encrypted data. ``` -3. aes算法使用 +3. AES usage - AES算法全称Advanced Encryption Standard,又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。 + Advanced Encryption Standard (AES), also known as the Rijndael algorithm, is a block encryption standard. - AES是对称加密,所以加密解密都需要用到同一个秘钥。 + AES is symmetric encryption, which means that the same key is required for encryption and decryption. - AES算法在本库的使用: + Use of the AES algorithm in this library: ``` - //第一步在需要使用到的页面,导入CryptoJS + // Step 1: Import CryptoJS on the page where it is needed. import { CryptoJS } from '@ohos/crypto-js' - //第二步定义加密解密需要用到的key + // Step 2: Define the key used for encryption and decryption. 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) //传参为加密后的内容及秘钥 + // Step 3: Call the AES encryption in the business logic where it is needed. + var encrypted = CryptoJS.AES.encrypt('hello world', key).toString() // The parameter is the content and key for encryption. + // Step 4: Call the AES decryption in the business logic where the above encrypted block needs to be decrypted. Note that the key must be the same. + var decrypted = CryptoJS.AES.decrypt(encrypted, key) // The parameter is the encrypted content and 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。 +For details about how to use other encryption algorithms, including the following, see the [demo](https://gitee.com/openharmony-sig/crypto-js/blob/master/entry/src/main/ets/pages/Index.ets), [XTS](https://gitee.com/openharmony-sig/crypto-js/tree/master/entry/src/ohosTest/ets/test), and [CryptoJS documentation](https://cryptojs.gitbook.io/docs/): -更多使用方法请参照 [demo](https://gitee.com/openharmony-sig/crypto-js/blob/master/entry/src/main/ets/pages/Index.ets) 和 [XTS](https://gitee.com/openharmony-sig/crypto-js/tree/master/entry/src/ohosTest/ets/test) 及 [参考原库使用文档](https://cryptojs.gitbook.io/docs/) +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 -## 接口列表 +## Available APIs - `crypto-js/md5` - `crypto-js/sha1` @@ -122,32 +122,32 @@ mode-cfb、mode-ctr、mode-ctr-gladman、mode-ofb、mode-ecb、pad-pkcs7、pad-a - `crypto-js/pad-zeropadding` - `crypto-js/pad-nopadding` -## 约束与限制 +## Constraints -在下述版本验证通过: -- 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) +This project has been verified in the following versions: +- DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API 12 Release (5.0.0.66) +- DevEco Studio: 5.0.3.122, SDK: API 12 (5.0.0.17) +- DevEco Studio: 4.1.3.600, SDK: API 11 (4.1.0.67) -## 目录结构 +## Directory Structure ```` |---- crypto-js -| |---- entry # 示例代码文件夹 -| |---- crypto # crypto-js库文件夹 -| |---- index.ts # 对外接口 +| |---- entry # Sample code +| |---- crypto # crypto-js library +| |---- index.ts # External APIs | |---- src | |---- main | |---- ets | |---- components -| |---- crypto.ts # 加密封装类 -| |---- README.md # 安装使用方法 +| |---- crypto.ts # Encryption encapsulation class +| |---- README_EN.md # Readme ```` -## 贡献代码 -使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/crypto-js/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) 。 +## How to Contribute +If you find any problem during the use, submit an [Issue](https://gitee.com/openharmony-sig/crypto-js/issues) or [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) to us. -## 开源协议 -本项目基于 [MIT License](https://gitee.com/openharmony-sig/crypto-js/blob/master/LICENSE) ,请自由地享受和参与开源。 +## License +This project is licensed under [MIT License](https://gitee.com/openharmony-sig/crypto-js/blob/master/LICENSE). -## 遗留问题 -- pbkdf2算法性能问题 \ No newline at end of file +## Known Issues +- Performance issues with the PBKDF2 algorithm diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..6250567 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,153 @@ +# crypto-js + +## 简介 + 本软件是移植开源软件 [crypto-js](https://github.com/brix/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](preview/preview.gif) + +## 下载安装 +```shell +ohpm install @ohos/crypto-js +``` +OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmony ohpm 包](https://gitee.com/openharmony-tpc/docs/blob/master/OpenHarmony_har_usage.md) +## 使用说明 +1. 引入依赖 + ``` +最新版本支持 + import { CryptoJS } from '@ohos/crypto-js' 或者 + import CryptoJS from '@ohos/crypto-js' + ``` +2. 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") //传参是需要加密的内容,返回值是加密后的数据 + ``` +3. 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。 + +更多使用方法请参照 [demo](https://gitee.com/openharmony-sig/crypto-js/blob/master/entry/src/main/ets/pages/Index.ets) 和 [XTS](https://gitee.com/openharmony-sig/crypto-js/tree/master/entry/src/ohosTest/ets/test) 及 [参考原库使用文档](https://cryptojs.gitbook.io/docs/) + + +## 接口列表 + +- `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](https://gitee.com/openharmony-sig/crypto-js/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) 。 + +## 开源协议 +本项目基于 [MIT License](https://gitee.com/openharmony-sig/crypto-js/blob/master/LICENSE) ,请自由地享受和参与开源。 + +## 遗留问题 +- pbkdf2算法性能问题 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index d5df605..74b0f34 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -25,8 +25,8 @@ struct Index { build() { Scroll(this.scroller) { Column() { - Button('跳转到测试TestDESTime界面') - .fontSize(20) + Button($r('app.string.Jump_page')) + .fontSize(15) .margin(20) .fontWeight(FontWeight.Bold) .onClick(() => { diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index abb2300..23fdc0c 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -11,6 +11,10 @@ { "name": "EntryAbility_label", "value": "crypto-js" + }, + { + "name": "Jump_page", + "value": "Jump to the TestDESTime page for testings" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index edf0c9b..6eaf00a 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,10 @@ { "name": "EntryAbility_label", "value": "crypto-js" + }, + { + "name": "Jump_page", + "value": "跳转到测试TestDESTime界面" } ] } \ No newline at end of file -- Gitee From 3be885d2e6ee2c667007e1d64688a8fef78d2265 Mon Sep 17 00:00:00 2001 From: hexagon1337 Date: Wed, 25 Sep 2024 12:29:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=95=8F=E6=84=9F?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hexagon1337 --- README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_zh.md b/README_zh.md index 6250567..d6079a7 100644 --- a/README_zh.md +++ b/README_zh.md @@ -144,7 +144,7 @@ mode-cfb、mode-ctr、mode-ctr-gladman、mode-ofb、mode-ecb、pad-pkcs7、pad-a ```` ## 贡献代码 -使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/crypto-js/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) 。 +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/crypto-js/issues) ,当然,也非常欢迎发 [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) 共建。 ## 开源协议 本项目基于 [MIT License](https://gitee.com/openharmony-sig/crypto-js/blob/master/LICENSE) ,请自由地享受和参与开源。 -- Gitee From c40262178b4d99d7c733f987726102ac728ca8d4 Mon Sep 17 00:00:00 2001 From: hexagon1337 Date: Wed, 25 Sep 2024 07:27:23 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=95=8F=E6=84=9F?= =?UTF-8?q?=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hexagon1337 --- README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_zh.md b/README_zh.md index d6079a7..0edf876 100644 --- a/README_zh.md +++ b/README_zh.md @@ -49,7 +49,7 @@ OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmon //第四步在需要把上面的加密块解密的业务逻辑,调用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 +其它加密算法使用方式,如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。 -- Gitee