Skip to content

Commit

Permalink
Added stronger encryption for data_private.json
Browse files Browse the repository at this point in the history
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
AnthyG committed Apr 15, 2017
1 parent 3ec8b70 commit 4a8ab6c
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 92 deletions.
79 changes: 79 additions & 0 deletions disabled/testPrivateCrypto.js
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)
}
})
})
})
}
178 changes: 132 additions & 46 deletions js/all.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4a8ab6c

Please sign in to comment.