diff --git a/en/react-native-secure-key-store.md b/en/react-native-secure-key-store.md index 57e2d832f5fbf202685acc2d71a020731961b15f..564e917228462fc0d9c8aa09b3c80b3d99e9d55f 100644 --- a/en/react-native-secure-key-store.md +++ b/en/react-native-secure-key-store.md @@ -16,15 +16,16 @@ ## Installation and Usage -Please check the release information of the third-party library for the matching version information: +Please go to the Releases page of the third-party library to check the matching version information: -| Library Version | Release Information | Supported RN Version | -| ---------- | ------------------------------------------------------------ | ---------- | -| 2.0.11 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases) | 0.72, 0.77 | +| Library Version | Release Info | Supported RN Version | +| --------------- | ------------------------------------------------------------ | -------------------- | +| 2.0.11 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases/2.0.11-rc.1) | 0.72 | +| 2.1.0 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases/2.1.0-rc.1) | 0.77 | -For older versions not published to npm, please refer to the [Installation Guide](/en/tgz-usage.md) to install the tgz package. +For older versions not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package. -Go to the project directory and execute the following instruction: +Enter the project directory and run the following command: @@ -44,7 +45,7 @@ yarn add @react-native-ohos/react-native-secure-key-store The following code shows the basic usage scenarios of this library: -> [!WARNING] The library name imported remains unchanged. +> [!WARNING] The library name imported remains unchanged when using. ```ts import React, { useState } from "react"; @@ -187,18 +188,14 @@ const styles = StyleSheet.create({ }); export default AppDemo; - ``` -## Using Codegen -Version >= @react-native-ohos/react-native-secure-key-store@2.0.11, which has been adapted to codegen-lib to generate bridge code. - -This library has been adapted to Codegen. Before using it, you need to actively execute the generation of third-party library bridge code. For details, please refer to the Codegen Usage Documentation. - ## Link + This step is a guide for manually configuring native dependencies. -First, you need to open the HarmonyOS project harmony in the project using DevEco Studio. -### Add overrides field to oh-package.json in the project root directory +First, you need to use DevEco Studio to open the HarmonyOS project `harmony` in the project. + +### 1. Add overrides field to `oh-package.json` in the project root directory ```json { @@ -210,6 +207,8 @@ First, you need to open the HarmonyOS project harmony in the project using DevEc } ``` +### 2. Introduce Native Code + There are currently two methods: Import via har package (this method will be deprecated after the IDE improves related functions, and it is the preferred method currently); @@ -228,23 +227,22 @@ Open the entry/oh-package.json5 file and append the following dependencies: } ``` -Click the sync button at the top right corner. +Click the `sync` button in the upper right corner. -Or run this command in the terminal: +Or run in the terminal: ```bash cd entry ohpm install ``` -Method 2: Link the source code directly +Method 2: Link source code directly -> [!TIP] For direct source code linking, refer to [Direct Source Code Linking Instructions](/zh-cn/link-source-code.md) +> [!TIP] If you need to use direct source code linking, please refer to [Direct Source Code Linking Description](/en/link-source-code.md) +### 3. Configure CMakeLists and Introduce RTNSecureKeyStorePackage -### 4.Configure CMakeLists and import turbo_log - -open entry/src/main/cpp/CMakeLists.txt,add: +open entry/src/main/cpp/CMakeLists.txt, add: ```diff include(FetchContent) @@ -288,10 +286,9 @@ target_link_libraries(rnoh_app PUBLIC rnoh) target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) + target_link_libraries(rnoh_app PUBLIC rnoh_secure_key_store) # RNOH_END: manual_package_linking_2 - ``` -打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: +Open `entry/src/main/cpp/PackageProvider.cpp`, add: ```diff #include "RNOH/PackageProvider.h" @@ -310,12 +307,12 @@ std::vector> PackageProvider::getPackages(Package::Cont } ``` -### 5.在 ArkTs 侧引入 RNSecureKeyStorePackage +### 4. Introduce RNSecureKeyStorePackage on ArkTs side -open `entry/src/main/ets/RNPackagesFactory.ts`,add: +Open `entry/src/main/ets/RNPackagesFactory.ts`, add: ```diff - ... +... + import { RNSecureKeyStorePackage } from "@react-native-ohos/react-native-secure-key-store/ts"; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { @@ -326,29 +323,29 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 6.Run - -Click the sync button in the upper right corner. +### 5. Run -Alternatively, execute the following command in the terminal: +Click the `sync` button in the upper right corner. +Or run in the terminal: ```bash cd entry ohpm install ``` -Then compile and run the project. +Then compile and run. ## Constraints ### Compatibility -To use this library, you need to use the correct React-Native and RNOH versions. In addition, you need to use the matching DevEco Studio and the phone ROM. +To use this library, you need to use the correct React-Native and RNOH versions. In addition, you need to use the matching DevEco Studio and phone ROM. -PThe content of this document has been verified based on the following versions: -1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105; -2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112; +This document is verified based on the following versions: + +1. RNOH: 0.72.90; SDK: HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM: NEXT.0.0.105; +2. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; ## Technical Implementation @@ -357,18 +354,19 @@ PThe content of this document has been verified based on the following versions The HarmonyOS version uses the following technologies to implement secure storage: 1. **HUKS (HarmonyOS Universal KeyStore)** + - Uses AES-256-GCM encryption algorithm - Keys are stored in a system-level secure area - Provides hardware-level security protection - 2. **Preferences** + - Used to store encrypted data - Data is stored in JSON format (including cipherText, iv, authTag) ### Encryption Process ``` -Raw Data → AES-256-GCM Encryption → Base64 Encoding → Preferences Storage +Original Data → AES-256-GCM Encryption → Base64 Encoding → Preferences Storage ``` ## API @@ -380,6 +378,7 @@ Raw Data → AES-256-GCM Encryption → Base64 Encoding → Preferences Storage | RNSecureKeyStore.remove | Removes the key-value pair. | function | yes | iOS/Android | yes | ```typescript + ``` ## Platform Differences @@ -391,7 +390,7 @@ Raw Data → AES-256-GCM Encryption → Base64 Encoding → Preferences Storage | accessible Option | ❌ Ignored | ✅ Fully Supported | ❌ Ignored | | setResetOnAppUninstallTo | ❌ Ignored | ✅ Supported | ❌ Ignored | - ## License -This project is licensed under [The MIT License (MIT)](https://github.com/ovr/react-native-secure-key-store/blob/master/LICENSE). +This project is based on [The MIT License (MIT)](https://github.com/ovr/react-native-secure-key-store/blob/master/LICENSE), please freely enjoy and participate in open source. + diff --git a/zh-cn/react-native-secure-key-store.md b/zh-cn/react-native-secure-key-store.md index b69c3ca558f56a2574e3a51a71e997c4f1bf353e..b11f8c3c1bd1920925ab94a15a99b0e673af9d1a 100644 --- a/zh-cn/react-native-secure-key-store.md +++ b/zh-cn/react-native-secure-key-store.md @@ -15,11 +15,13 @@ > [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-secure-key-store) ## 安装与使用 + 请到三方库的 Releases 发布地址查看配套的版本信息: | 三方库版本 | 发布信息 | 支持RN版本 | | ---------- | ------------------------------------------------------------ | ---------- | -| 2.0.11 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases) | 0.72,0.77 | +| 2.0.11 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases/2.0.11-rc.1) | 0.72 | +| 2.1.0 | [@react-native-ohos/react-native-secure-key-store Releases](https://github.com/react-native-oh-library/react-native-secure-key-store/releases/2.1.0-rc.1) | 0.77 | 对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 @@ -186,14 +188,7 @@ const styles = StyleSheet.create({ }); export default AppDemo; - ``` -## 使用 Codegen - -Version >= @react-native-ohos/react-native-secure-key-store@2.0.11, 已适配codegen-lib生成桥接代码。 - -本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](/zh-cn/codegen.md)。 - ## Link 此步骤为手动配置原生依赖项的指导。 @@ -214,16 +209,15 @@ Version >= @react-native-ohos/react-native-secure-key-store@2.0.11, 已适配cod ### 2.引入原生端代码 -There are currently two methods: - -Import via har package (this method will be deprecated after the IDE improves related functions, and it is the preferred method currently); -Link source code directly. +当前有两种方式: -Method 1: Import via har package (recommended) +- 通过 HAR 包导入(IDE 功能完善后将废弃,目前推荐使用此方式); +- 直接链接源码。 -> [!TIP] The HAR package can be found in the harmony subfolder of the third-party library's installation directory. +方式一:通过 HAR 包导入(推荐) +> [!TIP] HAR 包位于三方库安装目录的 harmony 子文件夹中。 -Open the entry/oh-package.json5 file and append the following dependencies: +打开 entry/oh-package.json5 文件并追加以下依赖项: ```json "dependencies": { @@ -245,8 +239,7 @@ ohpm install > [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) - -### 4.配置 CMakeLists 和引入 RTNSecureKeyStorePackage +### 3.配置 CMakeLists 和引入 RTNSecureKeyStorePackage open entry/src/main/cpp/CMakeLists.txt,add: @@ -292,7 +285,6 @@ target_link_libraries(rnoh_app PUBLIC rnoh) target_link_libraries(rnoh_app PUBLIC rnoh_gesture_handler) + target_link_libraries(rnoh_app PUBLIC rnoh_secure_key_store) # RNOH_END: manual_package_linking_2 - ``` 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: @@ -314,12 +306,12 @@ std::vector> PackageProvider::getPackages(Package::Cont } ``` -### 5.在 ArkTs 侧引入 RNSecureKeyStorePackage +### 4.在 ArkTs 侧引入 RNSecureKeyStorePackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff - ... +... + import { RNSecureKeyStorePackage } from "@react-native-ohos/react-native-secure-key-store/ts"; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { @@ -330,7 +322,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 6.运行 +### 5.运行 点击右上角的 `sync` 按钮 @@ -350,6 +342,7 @@ ohpm install 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 本文档内容基于以下版本验证通过: + 1. RNOH:0.72.90; SDK:HarmonyOS NEXT Developer DB3; IDE: DevEco Studio: 5.0.5.220; ROM:NEXT.0.0.105; 2. RNOH:0.77.18; SDK:HarmonyOS 6.0.0 Release; IDE: DevEco Studio 6.0.0.858; ROM:6.0.0.112; @@ -360,11 +353,12 @@ ohpm install HarmonyOS 版本使用以下技术实现安全存储: 1. **HUKS (HarmonyOS Universal KeyStore)** + - 使用 AES-256-GCM 加密算法 - 密钥存储在系统级安全区域 - 提供硬件级别的安全保护 - 2. **Preferences** + - 用于存储加密后的数据 - 数据以 JSON 格式存储(包含 cipherText, iv, authTag) @@ -375,6 +369,7 @@ HarmonyOS 版本使用以下技术实现安全存储: ``` ## API + | Name | Description | Type | Required | Platform | HarmonyOS Support | | ----------------------- | -------------------------------------------- | -------- | -------- | ----------- | ----------------- | | RNSecureKeyStore.set | Securely stores the key-value pair. | function | yes | iOS/Android | yes | @@ -382,6 +377,7 @@ HarmonyOS 版本使用以下技术实现安全存储: | RNSecureKeyStore.remove | Removes the key-value pair. | function | yes | iOS/Android | yes | ```typescript + ``` ## 平台差异 @@ -393,7 +389,6 @@ HarmonyOS 版本使用以下技术实现安全存储: | accessible 选项 | ❌ 忽略 | ✅ 完整支持 | ❌ 忽略 | | setResetOnAppUninstallTo | ❌ 忽略 | ✅ 支持 | ❌ 忽略 | - ## 开源协议 本项目基于 [The MIT License (MIT)](https://github.com/ovr/react-native-secure-key-store/blob/master/LICENSE) ,请自由地享受和参与开源。