forked from react-native-oh-library/react-native-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeysHarmony.js
More file actions
70 lines (64 loc) · 2.41 KB
/
Copy pathkeysHarmony.js
File metadata and controls
70 lines (64 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/env node
/*
* Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
* Use of this source code is governed by a MIT license that can be
* found in the LICENSE file.
*/
const {
getKeys,
makeFileInAndroidMainAssetsFolder,
makeFileInHarmonyEtsFolder,
makeFileInHarmonyCppFolder,
getHarmonyOsEnvironmentFile,
generatePassword,
encrypt,
makeCppFileTemplate,
splitPrivateKeyInto3ChunksOfArray,
makeFileInCPPDir,
genTSType,
CPP_DIRECTORY_PATH,
RN_KEYS_HMOS_CPP_DIR,
HM_PROJECT_PATH
} = require('./src/util/common');
const { makeCryptographicModuleTemplateHarmony } = require('./src/util/keysFilesTemplateHarmony');
const { cmakeListTemplete } = require('./src/util/cmakeListsTempleteHarmony');
const { publicKeysToBuildProfile } = require('./src/util/generatePublicKeysToBuildProfile');
const makeHarmonyOSJnuFiles = () => {
// 根据 node环境变量 process.env 拿到要读取的文件名
const KEYS_FILE_NAME = getHarmonyOsEnvironmentFile();
// 获取键值对象
const allKeys = getKeys(KEYS_FILE_NAME);
const secureKeys = allKeys.secure;
const publicKeys = allKeys.public;
const stringifyKeys = JSON.stringify(secureKeys);
// 生成12位秘钥
const password = generatePassword();
// 使用crypto.js 加密
const privateKey = encrypt(stringifyKeys, password);
// 加密结果分为3段,返回的数组
const privateKeyIn3Chunks = splitPrivateKeyInto3ChunksOfArray(privateKey);
// cpp解密模板代码
const cppFileContent = makeCppFileTemplate(privateKeyIn3Chunks, password);
// 将上一步生成的模板代码写入 cpp目录下 crypto.cpp
const isDoneCryptoCppFile = makeFileInCPPDir(cppFileContent, 'crypto.cpp');
// 拷贝public所有字段到 harmony工程build-profile.json5中
const isDoneCopyPublicKeysToBuildProfile = publicKeysToBuildProfile(publicKeys);
const halfKey = privateKey.substr(privateKey.length / 2);
const cryptographicModuleFileContent = makeCryptographicModuleTemplateHarmony(halfKey);
const isDoneGenCmakeFile = makeFileInHarmonyCppFolder(
cmakeListTemplete(CPP_DIRECTORY_PATH),
'CMakeLists.txt'
);
const isDoneAddedPrivateKey = makeFileInHarmonyCppFolder(
cryptographicModuleFileContent,
'PrivateKey.h'
);
genTSType(allKeys);
console.info('react-native-keys', {
isDoneGenCmakeFile,
isDoneCryptoCppFile,
isDoneAddedPrivateKey,
isDoneCopyPublicKeysToBuildProfile
});
};
makeHarmonyOSJnuFiles();