-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added stronger encryption for
data_private.json
Managed to get the AES-Encryption for the local-saved sent messages working.. Just add 15 random characters to the recipients cert_user_id 😆
- Loading branch information
Showing
3 changed files
with
263 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
function testPrivateCrypto(oU) { | ||
var oU = oU || page.site_info.cert_user_id | ||
var randI = Math.random().toString(36).substr(2, 5) + Math.random().toString(36).substr(2, 5) + Math.random().toString(36).substr(2, 5) | ||
var boU = btoa(randI + oU) | ||
var sdata = { | ||
"private_messages": [] | ||
} | ||
|
||
page.cmd("eciesEncrypt", [ | ||
JSON.stringify({ | ||
"recipient": oU, | ||
"body": emojione.toShort("Hello :wave::smile:"), | ||
"date_added": parseInt(moment().utc().format("x")) | ||
}) | ||
], (res1) => { | ||
console.log("Ecies Encrypt", res1) | ||
|
||
page.cmd("aesEncrypt", [ | ||
res1, | ||
boU, | ||
boU | ||
], (res2) => { | ||
console.log("Aes Encrypt", res2) | ||
var di = sdata.private_messages.push({ | ||
"randI": randI, | ||
"message": res2[2] | ||
}) | ||
|
||
var json_raw = unescape(encodeURIComponent(JSON.stringify(sdata, undefined, '\t'))) | ||
var json_rawA = btoa(json_raw) | ||
|
||
page.cmd("fileWrite", [ | ||
"disabled/EXAMPLE.json", | ||
json_rawA | ||
], (res3) => { | ||
if (res3 == "ok") { | ||
|
||
page.cmd("fileQuery", [ | ||
"disabled/EXAMPLE.json", | ||
"private_messages" | ||
], (res4) => { | ||
console.log("File read", res4) | ||
|
||
for (var x in res4) { | ||
var y = res4[x] | ||
var E1msg = y.message | ||
console.log("At ", x, y, E1msg) | ||
|
||
if (E1msg) { | ||
page.cmd("aesDecrypt", [ | ||
boU, | ||
E1msg, | ||
boU | ||
], (E2msg) => { | ||
console.log("Aes Decrypt", E2msg) | ||
|
||
if (E2msg) { | ||
page.cmd("eciesDecrypt", E2msg, (res6) => { | ||
console.log("Ecies Decrypt", res6) | ||
|
||
var msg = JSON.parse(res6) | ||
if (msg) { | ||
console.log("Valid MSG", msg) | ||
} else { | ||
console.log("Invalid MSG", msg) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
} else { | ||
console.log("File write", res3) | ||
} | ||
}) | ||
}) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.