Javascript-js used multiple sides and then modulo, integer data overflow

Source: Internet
Author: User
We have a comprehensive experiment to use the Diffie-hellman algorithm to Exchange keys, to use multiple-side and then modulo, in phpThe end bypasses the integer data overflow problem, phpThere are:

bcmod(bcpow(5, 2067), 17509)

jsInside:

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)

jsInside:

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.

phpI 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. phpI 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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.