added example salt/iv api

This commit is contained in:
2024-06-02 18:40:08 -04:00
parent 0e243efc82
commit b4721c1214
2 changed files with 34 additions and 4 deletions
+31 -3
View File
@@ -11,7 +11,8 @@
margin: 20px; margin: 20px;
} }
form { form,
#displform {
max-width: 400px; max-width: 400px;
margin: auto; margin: auto;
} }
@@ -67,8 +68,9 @@
function togglePassword() { function togglePassword() {
const passwordInput = document.getElementById('passwordInput'); const passwordInput = document.getElementById('passwordInput');
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password'; const type = (passwordInput.getAttribute('type') === 'password') ? 'text' : 'password';
passwordInput.setAttribute('type', type); passwordInput.setAttribute('type', type);
document.querySelector('.view-password').innerText = (type === 'text') ? '🔒' : '👁️';
} }
async function sendToServer() { async function sendToServer() {
@@ -77,7 +79,7 @@
const isEncrypt = document.getElementById('encryptToggle').checked; const isEncrypt = document.getElementById('encryptToggle').checked;
const endpoint = isEncrypt ? '/encrypt' : '/decrypt'; const endpoint = isEncrypt ? '/encrypt' : '/decrypt';
const r = await fetch(endpoint, { fetch(endpoint, {
method: 'POST', method: 'POST',
body: formData, body: formData,
}) })
@@ -98,17 +100,35 @@
alert("ERROR!"); alert("ERROR!");
}); });
} }
async function getSaltAndIv() {
const response = await fetch('/getsaltandiv', { method: 'POST' });
const siv = await response.json();
const el = document.querySelector('#salivdisp');
el.innerHTML = `<code>IV: ${siv.iv}</code><br><code>Salt: ${siv.salt}</code>`;
}
</script> </script>
</head> </head>
<body> <body>
<div style="text-align: center; margin-bottom: 50px;">
<h1 style="margin-bottom: 10px;">A Simple File/Text Encryptor</h1>
<h2 style="margin-top: 5px;">Created by ION606</h2>
</div>
<form id="encryptDecryptForm"> <form id="encryptDecryptForm">
<hr>
<label for="fileInput">File</label> <label for="fileInput">File</label>
<input type="file" id="fileInput" name="file"> <input type="file" id="fileInput" name="file">
<h3>OR</h3>
<label for="textInput">Text</label> <label for="textInput">Text</label>
<input type="text" id="textInput" name="text"> <input type="text" id="textInput" name="text">
<br><br>
<hr>
<label for="passwordInput">Password</label> <label for="passwordInput">Password</label>
<div class="password-container"> <div class="password-container">
<input type="password" id="passwordInput" name="password" required> <input type="password" id="passwordInput" name="password" required>
@@ -121,6 +141,14 @@
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>
<div id="displform">
<button style="background-color: red; margin-bottom: 10px;" onclick="getSaltAndIv()">Get Example
Salt/IV</button>
<div id="salivdisp">
</div>
</div>
</body> </body>
</html> </html>
+3 -1
View File
@@ -1,7 +1,7 @@
import fs, { read } from 'fs'; import fs, { read } from 'fs';
import express from 'express'; import express from 'express';
import cors from 'cors'; import cors from 'cors';
import { encrypt, decrypt } from './enc.js'; import { encrypt, decrypt, encryptInitEnc } from './enc.js';
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import multer from 'multer'; import multer from 'multer';
import stream from 'stream'; import stream from 'stream';
@@ -49,4 +49,6 @@ app.post('/decrypt', upload.single('file'), (req, res) => {
}); });
app.post('/getsaltandiv', (_, res) => res.send(encryptInitEnc("I'M ENCRYPTED!", 'password')))
app.listen(PORT, () => console.log(`app listening on port ${PORT}`)); app.listen(PORT, () => console.log(`app listening on port ${PORT}`));