This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
Implementing RSA from Scratch in JavaScript
11–20 of 27 posts
Re: Implementing RSA from Scratch in JavaScript
#12This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
JS not only has BigInt, but it also has TypedArrays too. It even used to have SIMD support before they dropped it for WASM.
Re: Implementing RSA from Scratch in JavaScript
#13This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
I see the peer comments regarding big ints, but the OP is still right in that the presented code doesn't work, for more than one reason.
I agree with the sibling commenter that this seems to be automatically generated. The disclaimer is weird, you don't just use a random rsa implementation found in a blog post "with careful consideration and expert guidance". The article's structure is weird, it's just a bullet list of steps and then code dump. It gets many details wrong (code won't run, explanation seems to be mixing up euler & carmichael totients, ...). etc.
It is somewhat scary that this got to the front page at all.
Re: Implementing RSA from Scratch in JavaScript
#14This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
Re: Implementing RSA from Scratch in JavaScript
#15This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
Javascript has native BigInts, and there is already an RSA implementation using them: https://github.com/i404788/tiny-rsa
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
> The operations supported on BigInt values are not constant-time and are thus open to timing attacks. JavaScript BigInts therefore could be dangerous for use in cryptography without mitigating factors.
Without checking the source code to understand their exact implementation, it seems questionable to implement cryptography algorithms for serious use in JavaScript.
Re: Implementing RSA from Scratch in JavaScript
#16This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
The OP's code needed a little help; there were some missing functions, misnamed calls, and he didn't use js BigInts (which are built-in to the browser, and you can use them as literals by appending 'n' to a number.)
See (and run) the fixed up code here: https://simpatico.io/crypto.md#rsafromscratch
EDIT: for my own crypto needs in the browser I use `subtle.crypto` with ECDH - https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93...
Re: Implementing RSA from Scratch in JavaScript
#17Re: Implementing RSA from Scratch in JavaScript
#18This isn't a particularly good way to learn RSA, and Javascript isn't a good environment to teach it. It's better to use Python, which at least has bignums. And obviously, seeing a wrong implementation of RSA isn't at all essential for implementing secure systems, contrary to the article's claims. Few people will actually need to implement RSA, and for those people, all those details that the article gets wrong reall…
Yeah, the implementation here obviously has problems, but as a learning exercise, I do still think it's worth implementing RSA (or anything else complex) in whatever language you're comfortable with. Personally, I implemented RSA in JavaScript back in 1998 as an exercise. I had to roll my own basic BigNum implementation and it didn't perform well enough to handle non-trivial key or message sizes, but I still think it…
Re: Implementing RSA from Scratch in JavaScript
#19Earlier quoted context omitted.
JS not only has BigInt, but it also has TypedArrays too. It even used to have SIMD support before they dropped it for WASM.
Not sure why all these responses point out that BigInt is supported in Javascript these days. The fact remains that the code in the article doesn't use BigInt and 'numbers' aren't automatically promoted.
> It's better to use Python, which at least has bignums.
Re: Implementing RSA from Scratch in JavaScript
#20Earlier quoted context omitted.
Javascript has native BigInts, and there is already an RSA implementation using them: https://github.com/i404788/tiny-rsa
That's funny -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... > The operations supported on BigInt values are not constant-time and are thus open to timing attacks. JavaScript BigInts therefore could be dangerous for use in cryptography without mitigating factors. Without checking the source code to understand their exact implementation, it seems questionable to implement cryptography algorithms for…