Compare commits

..

No commits in common. "cff32999ba15bb1f0dd57ff4ca7bc4cda5ffc453" and "b9a56f38f598ade8dc325894e2c4d90a0d4fda3c" have entirely different histories.

16 changed files with 139 additions and 5169 deletions

View File

@ -1,21 +0,0 @@
env:
browser: true
es2021: true
extends: eslint:recommended
overrides: []
parserOptions:
ecmaVersion: latest
sourceType: module
rules:
indent:
- error
- tab
linebreak-style:
- error
- unix
quotes:
- error
- double
semi:
- error
- always

3
.gitignore vendored
View File

@ -1,3 +0,0 @@
tags
node_modules/
dist/

View File

@ -3,11 +3,15 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>encryptme: Simple AES encryption/decryption</title>
<meta name="description" content="Easy to use and simple online tool for AES encryption and decryption.
Advanced settings allow control over the IV, AES mode, and PBKDF2 parameters.">
</head>
<body>
<script src="scripts/header-template.js"></script>
<h1>AES</h1>
<script src="scripts/interface.js"></script>
<script src="scripts/aes.js"></script>
</body>
</html>

13
dist/aes.html vendored
View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>encryptme: Simple AES encryption/decryption</title>
<meta name="description" content="Easy to use and simple online tool for AES encryption and decryption.
Advanced settings allow control over the IV, AES mode, and PBKDF2 parameters.">
<script defer src="src_style_css-src_templates_js.js"></script><script defer src="aes.js"></script></head>
<body>
<h1>AES</h1>
</body>
</html>

14
dist/index.html vendored
View File

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>encryptme</title>
<meta name="description" content="Easy to use and simple online tools for encryption and decryption.">
<script defer src="src_style_css-src_templates_js.js"></script><script defer src="index.js"></script></head>
<body>
<h2>Tools</h2>
<h3>Encryption/decryption</h3>
<a href="aes.html">AES</a>
</body>
</html>

View File

@ -3,10 +3,12 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>encryptme</title>
<meta name="description" content="Easy to use and simple online tools for encryption and decryption.">
</head>
<body>
<script src="scripts/header-template.js"></script>
<h2>Tools</h2>
<h3>Encryption/decryption</h3>
<a href="aes.html">AES</a>

4871
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
{
"name": "encryptme",
"version": "0.4.1",
"description": "Simple online cryptography app.",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"lint": "eslint --ext .js,.jsx src"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dogeystamp/encryptme.git"
},
"keywords": [
"website",
"cryptography",
"encryption",
"aes",
"webapp",
"aes-256",
"aes-gcm",
"decryption",
"encryption-decryption",
"cryptography-tools",
"cryptography-utilities"
],
"author": "dogeystamp",
"license": "BSD-2-Clause",
"bugs": {
"url": "https://github.com/dogeystamp/encryptme/issues"
},
"homepage": "https://github.com/dogeystamp/encryptme#readme",
"devDependencies": {
"css-loader": "^6.7.3",
"eslint": "^8.33.0",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
}
}

View File

@ -12,13 +12,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*/
import { generateHeader } from "./templates.js";
import "./style.css";
generateHeader();
import { TabList } from "./interface.js";
import { bufToB64, b64ToBuf } from "./util.js";
let tabs = new TabList({});
let encForm = tabs.createForm({label: "Encryption"});
@ -30,7 +23,7 @@ let encMsg = encForm.createTextArea({
let encPass = encForm.createPasswordInput({
label: "Password",
placeholder: "Enter your password",
enabledFunc: function() {return !encManualKey.value;}
enabledFunc: function() {return !encManualKey.value}
});
let encPbkdf2Iters = encForm.createNumberInput({
label: "PBKDF2 iterations",
@ -38,14 +31,14 @@ let encPbkdf2Iters = encForm.createNumberInput({
step: 1,
value: 300000,
advanced: true,
enabledFunc: function() {return !encManualKey.value;}
enabledFunc: function() {return !encManualKey.value}
});
let encSalt = encForm.createMediumTextBox({
label: "PBKDF2 salt",
dataType: "b64",
advanced: true,
enabled: false,
enabledFunc: function() {return encManualSalt.value && !encManualKey.value;}
enabledFunc: function() {return encManualSalt.value && !encManualKey.value}
});
let encManualSalt = encForm.createCheckBox({
label: "Use fixed salt instead of random",
@ -70,7 +63,7 @@ let encKey = encForm.createMediumTextBox({
dataType: "b64",
advanced: true,
enabled: false,
enabledFunc: function() {return encManualKey.value;}
enabledFunc: function() {return encManualKey.value}
});
let encManualKey = encForm.createCheckBox({
label: "Use fixed key instead of password",
@ -80,25 +73,25 @@ let encIV = encForm.createMediumTextBox({
label: "IV",
dataType: "b64",
advanced: true,
enabledFunc: function() {return encManualIV.value;},
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value);}
enabledFunc: function() {return encManualIV.value},
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value)}
});
let encManualIV = encForm.createCheckBox({
label: "Use fixed IV instead of random",
advanced: true,
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value);}
visibleFunc: function() {return ["AES-GCM", "AES-CBC"].includes(encMode.value)}
});
let encCounter = encForm.createMediumTextBox({
label: "Counter",
dataType: "b64",
advanced: true,
enabledFunc: function() {return encManualCounter.value;},
visibleFunc: function() {return encMode.value === "AES-CTR";}
enabledFunc: function() {return encManualCounter.value},
visibleFunc: function() {return encMode.value === "AES-CTR"}
});
let encManualCounter = encForm.createCheckBox({
label: "Use fixed counter instead of random",
advanced: true,
visibleFunc: function() {return encMode.value === "AES-CTR";}
visibleFunc: function() {return encMode.value === "AES-CTR"}
});
let encMode = encForm.createDropDown({
label: "AES mode",
@ -139,14 +132,14 @@ let decMsg = decForm.createTextArea({
let decPass = decForm.createPasswordInput({
label: "Password",
placeholder: "Enter your password",
enabledFunc: function() {return !decManualKey.value;}
enabledFunc: function() {return !decManualKey.value}
});
let decKey = decForm.createMediumTextBox({
label: "Key",
dataType: "b64",
advanced: true,
enabled: false,
enabledFunc: function() {return decManualKey.value;}
enabledFunc: function() {return decManualKey.value}
});
let decManualKey = decForm.createCheckBox({
label: "Use fixed key instead of password",
@ -272,18 +265,19 @@ encButton.handle.addEventListener("click", async function() {
let ciphertext;
switch (encMode.value) {
case "AES-GCM":
ciphertext = await aesGcmEnc(key, iv, msgEncoded);
break;
case "AES-CBC":
ciphertext = await aesCbcEnc(key, iv, msgEncoded);
break;
case "AES-CTR":
ciphertext = await aesCtrEnc(key, counter, msgEncoded);
break;
default:
encMode.handleError(Error(`Mode '${encMode.value}' is not implemented.`));
return;
case "AES-GCM":
ciphertext = await aesGcmEnc(key, iv, msgEncoded);
break;
case "AES-CBC":
ciphertext = await aesCbcEnc(key, iv, msgEncoded);
break;
case "AES-CTR":
ciphertext = await aesCtrEnc(key, counter, msgEncoded);
break;
default:
let e = Error(`Mode '${encMode.value}' is not implemented.`);
encMode.handleError(e);
return;
}
encOutRaw.value = ciphertext;
@ -296,7 +290,7 @@ encButton.handle.addEventListener("click", async function() {
"encMode": encMode.value,
"encKeySize": encKeySize.value,
"pbkdf2Iters": pbkdf2Iters,
};
}
});
async function aesGcmDec(key, iv, ciphertext) {
@ -386,18 +380,18 @@ decButton.handle.addEventListener("click", async function() {
try {
switch (encMode) {
case "AES-GCM":
plaintext = await aesGcmDec(key, iv, ciphertext);
break;
case "AES-CBC":
plaintext = await aesCbcDec(key, iv, ciphertext);
break;
case "AES-CTR":
plaintext = await aesCtrDec(key, counter, ciphertext);
break;
default:
throw Error(`Mode '${encMode.value}' is not implemented.`);
}
case "AES-GCM":
plaintext = await aesGcmDec(key, iv, ciphertext);
break;
case "AES-CBC":
plaintext = await aesCbcDec(key, iv, ciphertext);
break;
case "AES-CTR":
plaintext = await aesCtrDec(key, counter, ciphertext);
break;
default:
throw Error(`Mode '${encMode.value}' is not implemented.`);
}
} catch (e) {
if (e.message !== "" && e.message !== undefined) {
decMsg.handleError(e, "Error during decryption.");

View File

@ -0,0 +1,8 @@
header = document.createElement("div");
header.classList.add("page-header");
header.innerHTML = `
<a href="index.html"><h1>encryptme</h1></a>
`
document.body.appendChild(header);

View File

@ -12,8 +12,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*/
import { b64ToBuf, bufToB64 } from "./util.js";
class InterfaceElement {
rootNodes = [];
@ -107,7 +105,7 @@ class Form extends InterfaceElement {
}
let advancedToggle = this.createCheckBox({label: "Advanced settings"});
advancedToggle.handle.addEventListener("change", function() {
advancedToggle.handle.addEventListener('change', function() {
this.advanced = advancedToggle.value;
}.bind(this));
@ -181,7 +179,7 @@ class Form extends InterfaceElement {
createMediumTextBox(params) {
params.tag = document.createElement("textarea");
params.tag.classList.add("mediumbox");
params.tag.classList.add("mediumbox")
dataTypeSupports(params, ["plaintext", "b64", "json-b64"]);
return this.createElem(params);
}
@ -283,11 +281,30 @@ class Form extends InterfaceElement {
}
}
function b64ToBuf (b64) {
let ascii = atob(b64);
let buf = new ArrayBuffer(ascii.length);
let bytes = new Uint8Array(buf);
for (var i = 0; i < ascii.length; i++) {
bytes[i] = ascii.charCodeAt(i);
}
return buf;
}
function bufToB64 (buf) {
let bytes = new Uint8Array(buf);
let ascii = '';
for (var i = 0; i < bytes.byteLength; i++) {
ascii += String.fromCharCode(bytes[i]);
}
return btoa(ascii);
}
class FormElement extends InterfaceElement {
constructor({tag, fragment, advanced=false, form,
value, dataType, placeholder,
labelTag, label="",
enabledFunc,
enabled=true, enabledFunc,
visibleFunc
}) {
let oriVisibleFunc = visibleFunc;
@ -298,7 +315,7 @@ class FormElement extends InterfaceElement {
visibleFunc: function() {
let res;
if (oriVisibleFunc) {
res = oriVisibleFunc();
res = oriVisibleFunc()
} else {
res = true;
}
@ -338,62 +355,61 @@ class FormElement extends InterfaceElement {
get value() {
this.clearAlerts();
switch (this.dataType) {
case "number":
if (this.handle.checkValidity() == false) {
this.alertBox("alert-error", this.handle.validationMessage);
case "number":
if (this.handle.checkValidity() == false) {
this.alertBox("alert-error", this.handle.validationMessage);
return undefined;
}
return Number(this.handle.value);
case "plaintext":
return this.handle.value;
case "b64":
try {
return b64ToBuf(this.handle.value);
} catch (e) {
this.alertBox("alert-error", "Invalid base64 value.");
return;
}
case "json-b64":
let jsonString;
try {
jsonString = atob(this.handle.value);
} catch (e) {
this.alertBox("alert-error", "Invalid base64 value.");
return;
}
try {
return JSON.parse(jsonString);
} catch (e) {
this.alertBox("alert-error", "Invalid JSON encoding.");
return;
}
case "bool":
return this.handle.checked;
case "category":
return this.handle.value;
case "none":
return undefined;
}
return Number(this.handle.value);
case "plaintext":
return this.handle.value;
case "b64":
try {
return b64ToBuf(this.handle.value);
} catch (e) {
this.handleError(Error("Invalid base64 value."));
return undefined;
}
case "json-b64": {
let jsonString;
try {
jsonString = atob(this.handle.value);
} catch (e) {
this.handleError(Error("Invalid base64 value."));
return undefined;
}
try {
return JSON.parse(jsonString);
} catch (e) {
this.handleError(Error("Invalid JSON encoding."));
return undefined;
}
}
case "bool":
return this.handle.checked;
case "category":
return this.handle.value;
default:
return undefined;
}
}
set value(x) {
switch (this.dataType) {
case "number":
case "plaintext":
this.handle.value = x;
break;
case "b64":
this.handle.value = bufToB64(x);
break;
case "json-b64":
this.handle.value = btoa(JSON.stringify(x));
break;
case "bool":
this.handle.checked = x;
break;
case "category":
this.handle.value = x;
break;
case "number":
case "plaintext":
this.handle.value = x;
break;
case "b64":
this.handle.value = bufToB64(x);
break;
case "json-b64":
this.handle.value = btoa(JSON.stringify(x));
break;
case "bool":
this.handle.checked = x;
break;
case "category":
this.handle.value = x;
break;
}
}
@ -402,24 +418,24 @@ class FormElement extends InterfaceElement {
// type is alert-error or alert-info
if (this.handle === undefined) {
throw "can not add alert: still undefined";
throw `can not add alert: still undefined`;
}
if (this.hidden === true) {
throw "can not add alert: hidden";
throw `can not add alert: hidden`;
}
if (title === undefined) {
switch (type) {
case "alert-info":
title = "Info: ";
break;
case "alert-error":
title = "Error: ";
break;
default:
title = "";
break;
case "alert-info":
title = "Info: ";
break;
case "alert-error":
title = "Error: ";
break;
default:
title = "";
break;
}
}
@ -467,7 +483,7 @@ class Tab extends InterfaceElement {
class TabList extends InterfaceElement {
constructor({tag, par=document.body}) {
super({});
super({})
this.par = par;
@ -481,7 +497,7 @@ class TabList extends InterfaceElement {
par.appendChild(this.fragment);
}
tabs = [];
tabs = []
#activeForm;
set activeForm(x) {
@ -511,7 +527,7 @@ class TabList extends InterfaceElement {
});
this.tabs.push(tab);
tab.handle.addEventListener("click", function() {
tab.handle.addEventListener('click', function() {
this.activeForm = form;
}.bind(this));
@ -523,5 +539,3 @@ class TabList extends InterfaceElement {
return form;
}
}
export { TabList, FormElement, Form };

View File

@ -1,3 +0,0 @@
import { generateHeader } from "./templates.js";
import "./style.css";
generateHeader();

View File

@ -1,11 +0,0 @@
function generateHeader() {
let header = document.createElement("div");
header.classList.add("page-header");
header.innerHTML = `
<a href="index.html"><h1>encryptme</h1></a>
`;
document.body.prepend(header);
}
export { generateHeader };

View File

@ -1,34 +0,0 @@
/*
Copyright 2023 dogeystamp <dogeystamp@disroot.org>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
function b64ToBuf (b64) {
let ascii = atob(b64);
let buf = new ArrayBuffer(ascii.length);
let bytes = new Uint8Array(buf);
for (var i = 0; i < ascii.length; i++) {
bytes[i] = ascii.charCodeAt(i);
}
return buf;
}
function bufToB64 (buf) {
let bytes = new Uint8Array(buf);
let ascii = "";
for (var i = 0; i < bytes.byteLength; i++) {
ascii += String.fromCharCode(bytes[i]);
}
return btoa(ascii);
}
export { b64ToBuf, bufToB64 };

View File

@ -1,40 +0,0 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const pages = ["index", "aes"];
module.exports = {
mode: 'development',
entry: pages.reduce((config, page) => {
config[page] = `./src/${page}.js`;
return config;
}, {}),
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
},
optimization: {
splitChunks: {
chunks: "all",
},
},
plugins: [].concat(
pages.map(
(page) =>
new HtmlWebpackPlugin({
inject: true,
template: `./src/pages/${page}.html`,
filename: `${page}.html`,
chunks: [page],
})
)
),
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
};