Skip to content

Commit ec03ef8

Browse files
authored
Merge pull request #14 from numandev1/chore/dynamic-password
chore: add dynamic password while encryption and decryption
2 parents 1a6a954 + ed32183 commit ec03ef8

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

ios/crypto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
}
1212

1313
string Crypto::getJniJsonStringyfyData(string key) {
14-
std::string base64Secret = "U2FsdGVkX18IH3Ety1jYeC427casDIBviIHEX4a/Wj9n+mC35JmTMbWv8gT8dAtrdSBM8zQWUBnqFWegV1JwQs311+PrBdKydxlIFoTY8OOGVvDKlKkxTuFzMvCOs9OHlrnvlhY9+Z6XbA4P9gLGOfalgZon3XQRwi7B5LlmtZA=";
15-
std::string password = "asdf@1234";
14+
std::string base64Secret = "U2FsdGVkX1/UMOtZDFe4MXICpo6PG1owJ05gsZlsm9+nw24Oiop5GfL4wxtjRIcQGioS4vu2ciGryMhLed9bi8zluac10wWaEMkf8PbcIZ8Erbtu3prN6H3AwpgyBTLN/Bawg8TxjhiOCFPb6PswGR5BjPYD8YF1O2tcgYECofE=";
15+
std::string password = "QWLqiT85EaY2";
1616
bool binary = false;
1717
std::string plaintext = decryptor::dec(base64Secret, password,binary);
1818

ios/privateKey.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define PRIVATE_KEY @{ @"privateKey":@"311+PrBdKydxlIFoTY8OOGVvDKlKkxTuFzMvCOs9OHlrnvlhY9+Z6XbA4P9gLGOfalgZon3XQRwi7B5LlmtZA=" };
1+
#define PRIVATE_KEY @{ @"privateKey":@"zluac10wWaEMkf8PbcIZ8Erbtu3prN6H3AwpgyBTLN/Bawg8TxjhiOCFPb6PswGR5BjPYD8YF1O2tcgYECofE=" };

keysAndroid.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#! /usr/bin/env node
22
const CryptoJS = require('crypto-js');
33

4-
const pass = 'asdf@1234';
4+
const generatePassword = () => {
5+
var length = 12,
6+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
7+
retVal = '';
8+
for (var i = 0, n = charset.length; i < length; ++i) {
9+
retVal += charset.charAt(Math.floor(Math.random() * n));
10+
}
11+
return retVal;
12+
};
13+
514
const encrypt = (message, password, _iv) => {
615
const encrypted = CryptoJS.AES.encrypt(message, password, {
716
iv: _iv,
@@ -29,8 +38,9 @@ const makeAndroidJnuFiles = () => {
2938
const allKeys = getKeys(KEYS_FILE_NAME);
3039
const secureKeys = allKeys.secure;
3140
const stringifyKeys = JSON.stringify(secureKeys);
32-
const privateKey = encrypt(stringifyKeys, pass);
33-
const cppFileContent = makeCppFileTemplateAndroid(privateKey);
41+
const password = generatePassword();
42+
const privateKey = encrypt(stringifyKeys, password);
43+
const cppFileContent = makeCppFileTemplateAndroid(privateKey, password);
3444
const isDoneCrypoCppFile = makeFileInCppAndroidDirectory(
3545
cppFileContent,
3646
'crypto.cpp'

keysIOS.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#! /usr/bin/env node
22
const CryptoJS = require('crypto-js');
33

4-
const pass = 'asdf@1234';
4+
const generatePassword = () => {
5+
var length = 12,
6+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
7+
retVal = '';
8+
for (var i = 0, n = charset.length; i < length; ++i) {
9+
retVal += charset.charAt(Math.floor(Math.random() * n));
10+
}
11+
return retVal;
12+
};
513
const encrypt = (message, password, _iv) => {
614
const encrypted = CryptoJS.AES.encrypt(message, password, {
715
iv: _iv,
@@ -33,8 +41,9 @@ const makeIosJnuFiles = () => {
3341
const secureKeys = allKeys.secure;
3442
const publicKeys = allKeys.public;
3543
const stringifyKeys = JSON.stringify(secureKeys);
36-
const privateKey = encrypt(stringifyKeys, pass);
37-
const cppFileContent = makeCppFileTemplateIOS(privateKey);
44+
const password = generatePassword();
45+
const privateKey = encrypt(stringifyKeys, password);
46+
const cppFileContent = makeCppFileTemplateIOS(privateKey, password);
3847
const isDoneCrypoCppFile = makeFileInIosDir(cppFileContent, 'crypto.cpp');
3948

4049
const hFileContent = makeHppFileTemplateIOS();

src/util/keysFilesTemplateAndroid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports.makeCppFileTemplateAndroid = (data) => {
1+
module.exports.makeCppFileTemplateAndroid = (data, password) => {
22
return `
33
#include "crypto.h"
44
#include <string>
@@ -12,7 +12,7 @@ module.exports.makeCppFileTemplateAndroid = (data) => {
1212
1313
string Crypto::getJniJsonStringyfyData(string key) {
1414
std::string base64Secret = "${data}";
15-
std::string password = "asdf@1234";
15+
std::string password = "${password}";
1616
bool binary = false;
1717
std::string plaintext = decryptor::dec(base64Secret, password,binary);
1818

src/util/keysFilesTemplateIos.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports.makeCppFileTemplateIOS = (data) => {
1+
module.exports.makeCppFileTemplateIOS = (data, password) => {
22
return `
33
#include "crypto.h"
44
#include <string>
@@ -13,7 +13,7 @@ module.exports.makeCppFileTemplateIOS = (data) => {
1313
1414
string Crypto::getJniJsonStringyfyData(string key) {
1515
std::string base64Secret = "${data}";
16-
std::string password = "asdf@1234";
16+
std::string password = "${password}";
1717
bool binary = false;
1818
std::string plaintext = decryptor::dec(base64Secret, password,binary);
1919

0 commit comments

Comments
 (0)