Add to prototype
This commit is contained in:
77
abac/templates/decrypt_and_forward.html
Normal file
77
abac/templates/decrypt_and_forward.html
Normal file
@@ -0,0 +1,77 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Decrypt and Forward</title>
|
||||
<script src="{% static 'abac/jsbn.js' %}"></script>
|
||||
<script src="{% static 'abac/jsbn2.js' %}"></script>
|
||||
<script src="{% static 'abac/prng4.js' %}"></script>
|
||||
<script src="{% static 'abac/rng.js' %}"></script>
|
||||
<script src="{% static 'abac/paillier.js' %}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
function getPrivateKeyFromWebStorage() {
|
||||
// Retrieve and parse the stored private key
|
||||
const storedPrivateKey = localStorage.getItem('privateKey');
|
||||
if (!storedPrivateKey) return null;
|
||||
|
||||
const parsedKey = JSON.parse(storedPrivateKey);
|
||||
|
||||
// Construct the public key from the stored value
|
||||
const n = new BigInteger(localStorage.getItem('publicKey'));
|
||||
const publicKey = new paillier.publicKey(2048, n);
|
||||
|
||||
// Construct the private key
|
||||
const lambda = new BigInteger(parsedKey.lambda);
|
||||
const privateKey = new paillier.privateKey(lambda, publicKey);
|
||||
|
||||
// Attach the x value
|
||||
privateKey.x = new BigInteger(parsedKey.x);
|
||||
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
// Assuming you have a method to get privateKey from local web storage
|
||||
let privateKey = getPrivateKeyFromWebStorage();
|
||||
|
||||
let encryptions = {{ encryptions_as_strings|safe }};
|
||||
let decryptedValues = [];
|
||||
|
||||
for(let enc of encryptions) {
|
||||
let bigIntEnc = new BigInteger(enc.toString());
|
||||
decryptedValues.push(privateKey.decrypt(bigIntEnc).toString(10));
|
||||
}
|
||||
|
||||
// Forward the decrypted values with a POST request
|
||||
let form = document.createElement("form");
|
||||
form.setAttribute("method", "post");
|
||||
form.setAttribute("action", "{% url 'abac:verify_decryption' %}");
|
||||
|
||||
let csrfField = document.createElement("input");
|
||||
csrfField.setAttribute("type", "hidden");
|
||||
csrfField.setAttribute("name", "csrfmiddlewaretoken");
|
||||
csrfField.setAttribute("value", "{{ csrf_token }}");
|
||||
form.appendChild(csrfField);
|
||||
|
||||
let tokenField = document.createElement("input");
|
||||
tokenField.setAttribute("type", "hidden");
|
||||
tokenField.setAttribute("name", "token");
|
||||
tokenField.setAttribute("value", "{{ token }}");
|
||||
form.appendChild(tokenField);
|
||||
|
||||
for(let dec of decryptedValues) {
|
||||
let input = document.createElement("input");
|
||||
input.setAttribute("type", "hidden");
|
||||
input.setAttribute("name", "decryptions");
|
||||
input.setAttribute("value", dec);
|
||||
form.appendChild(input);
|
||||
}
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,18 +0,0 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<h2>Upload Public Key</h2>
|
||||
<form method="post" class="mt-3">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="public_key">Paste your public key here:</label>
|
||||
<textarea id="public_key" name="public_key" class="form-control" rows="6" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload Public Key</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user