Guest User

Key client

a guest
Feb 4th, 2020
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var https=require('https'),
  2.     crypto=require('crypto'),
  3.     fs=require('fs');
  4. var ip='10.195.0.39';
  5. ip='localhost'; //enable if needed
  6. process.env.NODE_TLS_REJECT_UNAUTHORIZED="0";
  7. var hash;
  8. if(fs.existsSync('store.json')) fs.unlinkSync('store.json');
  9. function send(pPath,pPayload,pOnData) {
  10.     https.request({
  11.         protocol:'https:',
  12.         host:ip,
  13.         port:5500,
  14.         path: pPath,
  15.         method:'POST',
  16.         headers:{
  17.             'Content-Type':'application/octet-stream'
  18.         },
  19.         agent: false
  20.     },pOnData).end(pPayload);
  21. }
  22. send('/key','BINARY_KEY_DATA_32_BYTES_LENGTH_',(res)=>{
  23.     res.on('data',(chunk)=>{
  24.         hash=Buffer.from(chunk); //MUST be converted to buffer
  25.         console.log(hash);
  26.         send('/id',hash);
  27.     });
  28. });
RAW Paste Data