2021年4月23日星期五

Initialization Vector (IV) -> toString('hex') -> write to file -> read from file-> hex to bin-> UndefinedUndefined Etc. NodeJS

I am trying to store an Initialization Vector as a string hex, then retrieve it back to binary, but when I go to print the result to the console, it says the following:

fIV: undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined; Passphrase: passrig  

Why is it printing undefined? And how can I achieve the desired result? Assume that the IV is generated correctly...

Relevant code:

SignIn(pass)  {      console.log(`fIV: ${h2b(fIV)}; Passphrase: ${pass}`);      const key = crypto.scryptSync(pass, 'baethrowssalt', 32);      var decipher = crypto.createDecipheriv(algorithm, key, h2b(fIV));       var decrypted = decipher.update(secret, 'hex', 'binary') + decipher.final('binary');        if(encrypted !== crypto.createCipheriv(algorithm, key).update(decrypted,'binary','hex') + cipher.final('hex'))      {          return alert(`access denied: encrypted:${encrypted}, secret:${secret}`);      };      return Buffer.from(decrypted, 'hex');    }    h2b(hex){      return (parseInt(hex, 16).toString(2)).padStart(8, '0');  }  

Relevant snippet in the SignUp function, I am writing to the IV file with:

   fs.writeFileSync(fileIV, iv.toString('hex'));  
https://stackoverflow.com/questions/67238509/initialization-vector-iv-tostringhex-write-to-file-read-from-file April 24, 2021 at 09:19AM

没有评论:

发表评论