cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.51k stars 264 forks source link

WebCrypto Support #184

Open ImSingee opened 2 years ago

ImSingee commented 2 years ago

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

zebp commented 2 years ago

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.

ImSingee commented 2 years ago

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.

maxcountryman commented 2 years ago

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

Perksey commented 8 months ago

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