Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Created May 15, 2024 03:46
Show Gist options
  • Save EncodeTheCode/8622b127f78e25388b265149bf11d442 to your computer and use it in GitHub Desktop.
Save EncodeTheCode/8622b127f78e25388b265149bf11d442 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Secure Form Submission</title>
<script>
// Function to encrypt form data using the generated public key
function encryptFormData(form) {
// Get the generated public key from the keygen element
var publicKey = form.elements['encryption-key'].value;
// Loop through form elements to encrypt their values
for (var i = 0; i < form.elements.length; i++) {
var element = form.elements[i];
// Skip elements that are not user input fields
if (element.tagName !== 'INPUT' && element.tagName !== 'TEXTAREA') {
continue;
}
// Encrypt the value using the public key
var encryptedValue = encryptWithPublicKey(element.value, publicKey);
// Update the element's value with the encrypted value
element.value = encryptedValue;
}
}
// Dummy function for encryption (replace with your actual encryption function)
function encryptWithPublicKey(data, publicKey) {
// This is just a placeholder; replace it with actual encryption logic
// For demonstration purposes, we'll just return the original data
return data;
}
</script>
</head>
<body>
<form action="/submit" method="post" onsubmit="encryptFormData(this)">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<!-- The keygen element to generate the public key -->
<label>Encryption Key:</label>
<keygen name="encryption-key"><br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment