Skip to content

Commit

Permalink
Create server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rasika-sarang authored Jul 15, 2024
0 parents commit 3e60f08
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const express = require('express');
const app = express();
const crypto = require('crypto');
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.post('/api/getdecryptedkey', (request, response) => {
console.log("Request Body", request.body);
const privateKey1 = crypto.createPrivateKey({
key: Buffer.from(request.body.enc_priv_key, 'base64'),
format: 'der',
type: 'pkcs8',
});

const publicKey2 = crypto.createPublicKey({
key: Buffer.from(request.body.ondc_pub_key, 'base64'),
format: 'der',
type: 'spki',
});

const sharedKey12 = crypto.diffieHellman({
privateKey: privateKey1,
publicKey: publicKey2,
});

const iv = Buffer.alloc(0); // ECB doesn't use IV
const decipher = crypto.createDecipheriv('aes-256-ecb', sharedKey12, iv);

let decrypted = decipher.update(request.body.challenge, 'base64', 'utf8');
decrypted += decipher.final('utf8');
console.log('Decrypted crypto key:', decrypted);
response.json({ decrypted_key: decrypted });
});

const port = 5000;

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

0 comments on commit 3e60f08

Please sign in to comment.