We have a comprehensive experiment to use the Diffie-hellman algorithm to Exchange keys, to use multiple-side and then modulo, in
php
The end bypasses the integer data overflow problem,
php
There are:
bcmod(bcpow(5, 2067), 17509)
js
Inside:
Math.pow(5, 2067) % 17509
What to do?
That's the one that counts 15187
.
Reply content:
We have a comprehensive experiment to use the Diffie-hellman algorithm to exchange the key, to use multiple-side and then modulo, at the end of the php
integer data overflow problem, there php
are:
bcmod(bcpow(5, 2067), 17509)
js
Inside:
Math.pow(5, 2067) % 17509
What to do?
That's the one that counts 15187
.
To calculate a large number with infinite precision in JS: https://www.npmjs.org/package/big.js
To run a common cryptography algorithm in JS: Https://www.npmjs.org/package/crypto-js
In the JS
case of integers and floating-point types, all numbers are Number
.
The maximum value is Number.MAX_VALUE
, the exact value is 1.7976931348623157e+308.
If you exceed this value, the general will not be Number
able to meet your needs, you may need to implement a large integer data structure.
php
I don't know much about it, but I know it will ruby
automatically convert to a large integer if the number exceeds the maximum value. php
I guess I did the same thing.
If it's a solution, you can write a quick power to your handwriting. or direct violence.
Need to use JS to achieve large integer arithmetic this matter before you have said, you use bcpow
is actually PHP large integer implementation (BC Library)
What I want to say is, from the practical point of view, the key exchange this thing should not use JS to calculate, the browser side behavior first is unsafe, second also very easy to be stolen. The use of HTTPS protocol and formal certificate can guarantee the security of JS and HTML code, but if the use of HTTPS, the key exchange and other things are encapsulated in the protocol stack, JS code does not have the need to calculate the key