Last active
November 11, 2021 06:41
-
-
Save ggicci/a7699ff9509b6c739077cb117af39158 to your computer and use it in GitHub Desktop.
CryptoJS - Get MD5 of Binary Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CryptoMD5 from "crypto-js/md5"; | |
import CryptoLatin1Encoder from "crypto-js/enc-latin1"; | |
function handleUploadClick(e: React.ChangeEvent<HTMLInputElement>) { | |
if (!e.target.files) { | |
return; | |
} | |
const selectedFile = e.target.files[0]; | |
const reader = new FileReader(); | |
reader.readAsBinaryString(selectedFile); | |
reader.onloadend = (e) => { | |
// Calculate md5 by using CryptoJS after content loaded. | |
// https://developer.mozilla.org/en-US/docs/Web/API/FileReader | |
const gotMD5 = CryptoMD5( | |
CryptoLatin1Encoder.parse(e.target!.result as string) | |
); | |
const hexMD4 = gotMD5.toString(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Find the demo here https://codesandbox.io/s/crypto-js-md5-of-binary-file-jl3eq