uuid-by-string icon indicating copy to clipboard operation
uuid-by-string copied to clipboard

Consider using `crypto` to generate md5/sha1 hashes

Open wovalle opened this issue 3 years ago • 8 comments

First of all, thank you for the library!

Have you considered using crypto.createHash to create md5/sha1 hashes instead of the js dependencies?

This would allow us to use your libraries in non-node runtimes like cloudflare workers (currently it fails because js-md5 contains eval which is usually a no-no for security reasons).

I created a temporary fork and replaced the dependencies for the native crypto and all tests passed succesfully, can create a PR if you agree.

Thanks!

wovalle avatar Oct 05 '22 20:10 wovalle

First of all, thank you for the library!

Have you considered using crypto.createHash to create md5/sha1 hashes instead of the js dependencies?

This would allow us to use your libraries in non-node runtimes like cloudflare workers (currently it fails because js-md5 contains eval which is usually a no-no for security reasons).

I created a temporary fork and replaced the dependencies for the native crypto and all tests passed succesfully, can create a PR if you agree.

Thanks!

Hi, is it possible to adapt this script to work in a browser?

doroved avatar Mar 13 '23 19:03 doroved

I think this library is only exported as a commonjs module. If it is exported as an esmodule + those two dependencies I mentioned are replaced, this would be 100% browser compatible.

wovalle avatar Mar 15 '23 08:03 wovalle

@wovalle where is this fork/repo at?

titanism avatar Aug 01 '24 10:08 titanism

We've published @forwardemail/uuid-by-string in the interim to npm. Can you please submit a PR so we can get this in the main repo of uuid-by-string for the wider npm community? @wovalle

titanism avatar Aug 01 '24 10:08 titanism

@wovalle one small note, you should add this to the top of your src/lib.js file before sending a PR over:

+const crypto = require('node:crypto');
src/lib.js
73:  return new Uint8Array(crypto.createHash("md5").update(buf).digest());
82:  return new Uint8Array(crypto.createHash("sha1").update(buf).digest());

Otherwise current tests do not pass:

Screen Shot 2024-08-01 at 5 15 18 AM

You can see we've done this already at: https://github.com/forwardemail/uuid-by-string/commit/ab07dd6ca1f14e9103ea53887713d41847e80a10

titanism avatar Aug 01 '24 10:08 titanism

First of all, so cool that a service I've used in the past (forwardemail) cloned one of my repos :D

Sure, just added node:crypto @titanism

wovalle avatar Aug 02 '24 21:08 wovalle

Also created the PR #37 to merge back to upstream. Rebased my changes on top of current master so the commit is clean 👍🏽

Let me know if you have any questions @danakt

wovalle avatar Aug 02 '24 21:08 wovalle