diff --git a/Project/Team_17/ui/css/ecdsa2.css b/Project/Team_17/ui/css/ecdsa2.css new file mode 100644 index 0000000..0236c9b --- /dev/null +++ b/Project/Team_17/ui/css/ecdsa2.css @@ -0,0 +1,47 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + margin: 0; + padding: 0; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + } + + #container { + background-color: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + padding: 20px; + width: 800px; + height: 500px; + text-align: center; + } + + label { + display: block; + margin-bottom: 8px; + font-weight: bold; + } + + input { + width: 100%; + padding: 8px; + margin-bottom: 16px; + box-sizing: border-box; + } + + button { + background-color: #007BFF; + color: #fff; + border: none; + padding: 10px 20px; + font-size: 16px; + cursor: pointer; + border-radius: 4px; + } + + button:hover { + background-color: #0056b3; + } \ No newline at end of file diff --git a/Project/Team_17/ui/index.html b/Project/Team_17/ui/index.html new file mode 100644 index 0000000..686daf8 --- /dev/null +++ b/Project/Team_17/ui/index.html @@ -0,0 +1,32 @@ + + + + + + ECDSA Signature Generator + + + + + + +
+

ECDSA Signature Generator

+ + + + + + + + +

Signature (r, s):

+

+ +

Signature Verification:

+

+
+ + + + \ No newline at end of file diff --git a/Project/Team_17/ui/js/ecdsa.js b/Project/Team_17/ui/js/ecdsa.js new file mode 100644 index 0000000..8419ff0 --- /dev/null +++ b/Project/Team_17/ui/js/ecdsa.js @@ -0,0 +1,54 @@ +document.getElementById('generateBtn').addEventListener('click', generateSignature); + +function generateSignature() { + const privateKeyHex = document.getElementById('privateKey').value; + const message = document.getElementById('message').value; + + // Validate input + if (!privateKeyHex || !message) { + alert('Please enter both private key and message.'); + return; + } + + try { + // Convert the private key from hex to bytes + const privateKeyBytes = hexToBytes(privateKeyHex); + + // Create an elliptic curve object using the secp256k1 curve + const ec = new elliptic.ec('secp256k1'); + + // Create a key pair from the private key + const key = ec.keyFromPrivate(privateKeyBytes); + + // Hash the message using SHA-256 + const hashedMessage = CryptoJS.SHA256(CryptoJS.enc.Utf8.parse(message)).toString(CryptoJS.enc.Hex); + + // Sign the hashed message + const signature = key.sign(hashedMessage); + + /* Modify the signature to make it invalid (for example, increment s) + signature.s = signature.s.add(ec.n); // This is just an example, you can modify it differently*/ + + // Display the signature in hex format + const signatureOutput = `(${signature.r.toString(16)}, ${signature.s.toString(16)})`; + document.getElementById('signatureOutput').innerText = signatureOutput; + + // Verification logic + const validSignature = key.verify(hashedMessage, signature); + + // Display the verification result + const verificationOutput = `Is Signature valid? : ${validSignature}`; + document.getElementById('verificationOutput').innerText = verificationOutput; + } catch (error) { + alert('Error: ' + error.message); + } +} + +// Hex to Bytes conversion +function hexToBytes(hex) { + const bytes = []; + for (let i = 0; i < hex.length; i += 2) { + bytes.push(parseInt(hex.substr(i, 2), 16)); + } + return new Uint8Array(bytes); +} \ No newline at end of file