Skip to content

Commit 0208404

Browse files
author
Luca Forstner
committed
fix(core): Use sha256 instead of md5 to generate uuids from string
1 parent e7f1af4 commit 0208404

File tree

1 file changed

+7
-9
lines changed
  • packages/bundler-plugin-core/src

1 file changed

+7
-9
lines changed

packages/bundler-plugin-core/src/utils.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,23 @@ function lookupPackageJson(cwd: string, stopAt: string): PackageJson | undefined
173173
* Deterministically hashes a string and turns the hash into a uuid.
174174
*/
175175
export function stringToUUID(str: string): string {
176-
const md5sum = crypto.createHash("md5");
177-
md5sum.update(str);
178-
const md5Hash = md5sum.digest("hex");
176+
const sha256Hash = crypto.createHash("sha256").update(str).digest("hex");
179177

180178
// Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)
181179
// RFC 4122 section 4.4
182-
const v4variant = ["8", "9", "a", "b"][md5Hash.substring(16, 17).charCodeAt(0) % 4] as string;
180+
const v4variant = ["8", "9", "a", "b"][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;
183181

184182
return (
185-
md5Hash.substring(0, 8) +
183+
sha256Hash.substring(0, 8) +
186184
"-" +
187-
md5Hash.substring(8, 12) +
185+
sha256Hash.substring(8, 12) +
188186
"-4" +
189-
md5Hash.substring(13, 16) +
187+
sha256Hash.substring(13, 16) +
190188
"-" +
191189
v4variant +
192-
md5Hash.substring(17, 20) +
190+
sha256Hash.substring(17, 20) +
193191
"-" +
194-
md5Hash.substring(20)
192+
sha256Hash.substring(20)
195193
).toLowerCase();
196194
}
197195

0 commit comments

Comments
 (0)