client-side encryption working

new-idea
Avril 4 years ago
parent 0a1f7e2293
commit 6265a8f41d
Signed by: flanchan
GPG Key ID: 284488987C31F630

9
.gitignore vendored

@ -1,9 +1,4 @@
/target
*~
# Added by cargo
#
# already existing elements were commented out
#/target
bower_components
node_modules

39
package-lock.json generated

@ -0,0 +1,39 @@
{
"name": "yuurei",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
"integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
"requires": {
"safer-buffer": "~2.1.0"
}
},
"crypto-js": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
},
"jsencrypt": {
"version": "3.0.0-rc.1",
"resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.0.0-rc.1.tgz",
"integrity": "sha512-gcvGaqerlUJy1Kq6tNgPYteVEoWNemu+9hBe2CdsCIz4rVcwjoTQ72iD1W76/PRMlnkzG0yVh7nwOOMOOUfKmg=="
},
"node-rsa": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/node-rsa/-/node-rsa-1.1.1.tgz",
"integrity": "sha512-Jd4cvbJMryN21r5HgxQOpMEqv+ooke/korixNNK3mGqfGJmy0M77WDDzo/05969+OkMy3XW1UuZsSmW9KQm7Fw==",
"requires": {
"asn1": "^0.2.4"
}
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
}
}
}

@ -0,0 +1,21 @@
{
"name": "yuurei",
"version": "0.1.0",
"description": "",
"main": "index.js",
"dependencies": {
"crypto-js": "^4.0.0",
"jsencrypt": "^3.0.0-rc.1",
"node-rsa": "^1.1.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.flanchan.moe:flanchan/yuurei.git"
},
"author": "",
"license": "GPL-3.0-or-later"
}

@ -5,6 +5,65 @@
</head>
<body>
<script src="js/crypto-js.js"></script>
<script src="js/jsencrypt.min.js"></script>
<script src="js/NodeRSA.js"></script>
<script type="text/javascript">
function test(priv, pub) {
//const priv = priv || document.getElementById("privkey").textContent;
//const pub = pub || document.getElementById("pubkey").textContent;
console.log(`Priv: ${priv}`);
console.log(`Pub: ${pub}`);
const encrypt = new JSEncrypt();
encrypt.setPublicKey(pub);
const ciphertext = encrypt.encrypt("test input");
console.log(`Ciphertext: ${ciphertext}`);
const decrypt = new JSEncrypt();
decrypt.setPrivateKey(priv);
const plaintext = decrypt.decrypt(ciphertext);
console.log(`Plaintext: ${plaintext}`);
const sign = new JSEncrypt();
sign.setPrivateKey(priv);
const signature = sign.sign("test input", CryptoJS.SHA256, "sha256");
console.log(`Signature: ${signature}`);
const verify = new JSEncrypt();
verify.setPublicKey(pub);
const verified = verify.verify("test input", signature, CryptoJS.SHA256);
console.log(`Verified: ${verified}`);
const key = "test key 123";
const aes_ciphertext = CryptoJS.AES.encrypt("test input", key).toString();
console.log(`AES ciphertext: ${aes_ciphertext}`);
const bytes = CryptoJS.AES.decrypt(aes_ciphertext, key);
const aes_plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log(`AES plaintext: ${aes_plaintext}`);
}
window.onload = (async() => {
const NodeRSA = require("node-rsa");
const key = new NodeRSA({b: 1024});
//key.generateKeyPair(); //unneeded I think
const pub = key.exportKey("public");
const priv = key.exportKey("private");
//console.log(`Pub: ${pub}, priv: ${priv}`);
document.getElementById("privkey").textContent = priv;
document.getElementById("pubkey").textContent = pub;
test(priv, pub);
});
</script>
<textarea id="privkey" rows="15" cols="65">(unbound)</textarea>
<textarea id="pubkey" rows="15" cols="65">(unbound)</textarea>
</body>
</html>

File diff suppressed because it is too large Load Diff

@ -0,0 +1 @@
../../bower_components/crypto-js/crypto-js.js

@ -0,0 +1 @@
../../node_modules/jsencrypt/bin/jsencrypt.min.js
Loading…
Cancel
Save