workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

WebCrypto Support

Open ImSingee opened this issue 2 years ago • 4 comments

I think it may be useful if support Web Crypto like web_sys

ImSingee avatar May 15 '22 16:05 ImSingee

I'm a little unsure if this will be worth it, I have two concerns.

  1. We're trying to be as rust-y as possible, so calling into APIs that look exactly like the browser kind of breaks that illusion.
  2. The bigger concern, is the overhead of calling into JS with all those copies vs just doing it in wasm worth it? Rust's crypto crates are usually pretty good but I'm not sure how fast they end up when compiled to wasm, I think we should do some benchmarks on this.

If we find that it probably isn't a good fit, users that do want to be able to use it should just be able to use web_sys.

zebp avatar May 16 '22 20:05 zebp

In fact, I just can't find a way to use crypto method as easy as just using WebCrypto .

I found https://github.com/RustCrypto/block-ciphers , but because of the Warning section in their README, I'm afraid of using them. And they are really low-level so I must do many things manualy.

I'm using MagicCrypt now but it do too many things besides of just an encrypt/decrypt.

So I think, proving a way for using Web Crypto may be useful in some case.

ImSingee avatar May 18 '22 00:05 ImSingee

In fact, I just can't find a way to use crypto method as easy as just using WebCrypto .

Have you given ring a try?

I've found it to be excellent, performing well when compiled to WASM. It's my go-to for encryption in Rust along with argon2 (for e.g. password hashing).

maxcountryman avatar Jul 09 '22 21:07 maxcountryman

Ring is a great suggestion, but I still find myself needing WebCrypto to get access to a secure RNG.

Perksey avatar Jan 08 '24 19:01 Perksey