Skip to content

Commit

Permalink
Merge pull request #14 from numandev1/chore/dynamic-password
Browse files Browse the repository at this point in the history
chore: add dynamic password while encryption and decryption
  • Loading branch information
numandev1 authored Jun 1, 2023
2 parents 1a6a954 + ed32183 commit ec03ef8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ios/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
}

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

Expand Down
2 changes: 1 addition & 1 deletion ios/privateKey.m
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PRIVATE_KEY @{ @"privateKey":@"311+PrBdKydxlIFoTY8OOGVvDKlKkxTuFzMvCOs9OHlrnvlhY9+Z6XbA4P9gLGOfalgZon3XQRwi7B5LlmtZA=" };
#define PRIVATE_KEY @{ @"privateKey":@"zluac10wWaEMkf8PbcIZ8Erbtu3prN6H3AwpgyBTLN/Bawg8TxjhiOCFPb6PswGR5BjPYD8YF1O2tcgYECofE=" };
16 changes: 13 additions & 3 deletions keysAndroid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#! /usr/bin/env node
const CryptoJS = require('crypto-js');

const pass = 'asdf@1234';
const generatePassword = () => {
var length = 12,
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
retVal = '';
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
};

const encrypt = (message, password, _iv) => {
const encrypted = CryptoJS.AES.encrypt(message, password, {
iv: _iv,
Expand Down Expand Up @@ -29,8 +38,9 @@ const makeAndroidJnuFiles = () => {
const allKeys = getKeys(KEYS_FILE_NAME);
const secureKeys = allKeys.secure;
const stringifyKeys = JSON.stringify(secureKeys);
const privateKey = encrypt(stringifyKeys, pass);
const cppFileContent = makeCppFileTemplateAndroid(privateKey);
const password = generatePassword();
const privateKey = encrypt(stringifyKeys, password);
const cppFileContent = makeCppFileTemplateAndroid(privateKey, password);
const isDoneCrypoCppFile = makeFileInCppAndroidDirectory(
cppFileContent,
'crypto.cpp'
Expand Down
15 changes: 12 additions & 3 deletions keysIOS.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#! /usr/bin/env node
const CryptoJS = require('crypto-js');

const pass = 'asdf@1234';
const generatePassword = () => {
var length = 12,
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
retVal = '';
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
};
const encrypt = (message, password, _iv) => {
const encrypted = CryptoJS.AES.encrypt(message, password, {
iv: _iv,
Expand Down Expand Up @@ -33,8 +41,9 @@ const makeIosJnuFiles = () => {
const secureKeys = allKeys.secure;
const publicKeys = allKeys.public;
const stringifyKeys = JSON.stringify(secureKeys);
const privateKey = encrypt(stringifyKeys, pass);
const cppFileContent = makeCppFileTemplateIOS(privateKey);
const password = generatePassword();
const privateKey = encrypt(stringifyKeys, password);
const cppFileContent = makeCppFileTemplateIOS(privateKey, password);
const isDoneCrypoCppFile = makeFileInIosDir(cppFileContent, 'crypto.cpp');

const hFileContent = makeHppFileTemplateIOS();
Expand Down
4 changes: 2 additions & 2 deletions src/util/keysFilesTemplateAndroid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports.makeCppFileTemplateAndroid = (data) => {
module.exports.makeCppFileTemplateAndroid = (data, password) => {
return `
#include "crypto.h"
#include <string>
Expand All @@ -12,7 +12,7 @@ module.exports.makeCppFileTemplateAndroid = (data) => {
string Crypto::getJniJsonStringyfyData(string key) {
std::string base64Secret = "${data}";
std::string password = "asdf@1234";
std::string password = "${password}";
bool binary = false;
std::string plaintext = decryptor::dec(base64Secret, password,binary);
Expand Down
4 changes: 2 additions & 2 deletions src/util/keysFilesTemplateIos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports.makeCppFileTemplateIOS = (data) => {
module.exports.makeCppFileTemplateIOS = (data, password) => {
return `
#include "crypto.h"
#include <string>
Expand All @@ -13,7 +13,7 @@ module.exports.makeCppFileTemplateIOS = (data) => {
string Crypto::getJniJsonStringyfyData(string key) {
std::string base64Secret = "${data}";
std::string password = "asdf@1234";
std::string password = "${password}";
bool binary = false;
std::string plaintext = decryptor::dec(base64Secret, password,binary);
Expand Down

0 comments on commit ec03ef8

Please sign in to comment.