3

There is big hex value:

var Hex = "ad6eb61316ff805e9c94667ab04aa45aa3203eef71ba8c12afb353a5c7f11657e43f5ce4483d4e6eca46af6b3bde4981499014730d3b233420bf3ecd3287a2768da8bd401f0abd7a5a137d700f0c9d0574ef7ba91328e9a6b055820d03c98d56943139075d";

How can I convert it to big integer in node.js? I tried to search, but what I found is

var integer = parseInt(Hex, 16);

But It doesn't work if I put big hex value. I think. the result is,

1.1564501846672726e+243

How can I return normal big integer? I want to use this value for modulus in RSA encryption. Actually I don't know I have to convert it or not.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
ton1
  • 7,238
  • 18
  • 71
  • 126
  • I wonder if this is a new acceptable answer using `BigInt`: https://stackoverflow.com/a/53751162/470749 – Ryan Jun 18 '20 at 18:43

1 Answers1

3

You need precise integers to do modular arithmetic for RSA, but the largest integer in JavaScript is 9007199254740991 without losing precision. You cannot represent a larger integer as a Number. You would need to devise a way to do modular arithmetic with many chunks of the large integer or simply use one of the available like the big number arithmetic in JSBN which also provides a full implementation of RSA including PKCS#1 v1.5 padding.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Thanks. I red your answer and found some document about that, but normal JSBN couldn't used without browser, Fortunately I found this github:https://github.com/eschnou/node-bignumber But I got an error. Do you know what is wrong? please visit the page :http://stackoverflow.com/questions/34180984/rsakey-is-not-defined-in-nodejs . – ton1 Dec 09 '15 at 14:16