brix / crypto-js

JavaScript library of crypto standards.
Other
15.83k stars 2.39k forks source link

Encrypt a whole file #140

Open Sagaryalioe opened 6 years ago

Sagaryalioe commented 6 years ago

How do you encrypt a whole file? Like zip, epub files and write the encrypted data to a file in storage. Thankyou.

LuffySmile commented 5 years ago

Do you solve the issue?

gamelife1314 commented 5 years ago

You can try the following code:

 let sha1Hash = CryptoJS.algo.SHA1.create();
 let md5Hash = CryptoJS.algo.MD5.create();
 const contentBuffer = fs.readFileSync('./test.png');
 const contentWordArray = CryptoJS.lib.WordArray.create(new Uint8Array(contentBuffer));
 sha1Hash = sha1Hash.update(contentWordArray);
 md5Hash = md5Hash.update(contentWordArray);
console.log(md5Hash.finalize().toString(CryptoJS.enc.Hex));
console.log(sha1Hash.finalize().toString(CryptoJS.enc.Hex));