I use the jar command to build jar files. While trying to cache the jar files using md5 signatures, I found that jars built from the exact same sources had different md5 signatures.
Upon closer inspection, I found that every time the jar was created the contents were exactly the same (diff -qr was empty). It turns out that the timestamp of creation is encoded in the jar file which throws off the md5 signature. Other people have discovered the same here.
There is even a blog post on how to create jar files identically each time with maven. However, I want a simple solution using the command line using readily available commands such as jar and zip (may have to do this on a server without install permissions), possibly leading to the same "functional" jar as I'm currently getting using jar command.
EDIT: For my purpose, it also suffices to quickly find the md5 so that it is the same across builds, even if the jars are not identical. The only way I found so far is to extract the files in the jar and to md5 all component files. But I'm afraid that is slow for bigger jars and is going to defeat the purpose of caching them to avoid building them in the first place. Is there a better and faster solution?
I have the following snippet
function runUpload( file ) { key_name = file.name if( file.type === 'image/png' || file.type === 'image/jpg' || file.type === 'image/jpeg' || file.type === 'image/gif' || file.type === 'image/bmp' ){ var reader = new FileReader(), image = new Image(); reader.readAsDataURL( file ); reader.onload = function( _file ){ keyhash = md5(atob(_file.target.result.split(',')[1])); ZZ('key').el.src = _file.target.result; ZZ('key').el.style.display = 'block'; } } }
The reason that the split happens is because if I left it at just:
_file.target.result
The resulting string would be:
data:text/plain;base64,SEVMTE8=
It uses https://raw.githubusercontent.com/blueimp/JavaScript-MD5/master/js/md5.min.js
The value of keyhash is different from when I do:
cat file.png | md5sum
Also when doing the python below, it gives me a different value to the JS version but the same as Linux
import hashlibdef md5Checksum(filePath): with open(filePath, 'rb') as fh: m = hashlib.md5() while True: data = fh.read(8192) if not data: break m.update(data) return m.hexdigest()print('The MD5 checksum of text.txt is', md5Checksum('000000.png'))
Am I missing something obvious or should they all return the same value?
JS: dc839221df178f70c08fa510a3d76a3b
Python and MD5SUM: 9310dad66d4a73e29a761fb724f2825
In fact, if I have a file called HELLO.txt and the only content in there is: HELLO
base64'ing it in Linux/Python give the same result which is different to when JS does it.
SEVMTE8K vs SEVMTE8=
I think it may be something to do with new lines, break likes, return carriages etc
JavaScript has it as one continuous stream whereas editing the file in an text editor shows line breaks
Thanks
I have a program that is supposed to download a file and check the hash value to the last time it was downloaded. If it is a new file, then save it. But something goes wrong. Because the hash of the last_unique file seems to change after copy, but then when running the program again, it is the same as first time. What goes wrong here?
const http = require('http');const fs = require('fs');const md5File = require('md5-file');const fileToDownload = "http://website.com/photo.jpg";const downloadFileSync = require('download-file-sync');var counter = 0; function getTimestamp() { var d = new Date(); var year = d.getFullYear(); var month = ("0" + (d.getMonth() + 1)).slice(-2); var date = ("0" + d.getDate()).slice(-2); var hours = d.getHours(); var minutes = d.getMinutes(); var seconds = d.getSeconds(); var timestamp = year + "-" + month + "-" + date + "_" + hours + "-" + minutes + "-" + seconds; return timestamp; }function request() { var content = downloadFileSync(fileToDownload); fs.writeFileSync('last_download.jpg', content); var hash1 = md5File.sync('last_download.jpg'); var hash2 = md5File.sync('last_unique.jpg'); if (hash1.localeCompare(hash2) != 0) { console.log('Unique file spotted!'); var h3 = md5File.sync('last_download.jpg'); console.log('last_download.jpg: ' + h3); var h4 = md5File.sync('last_unique.jpg'); console.log('last_unique.jpg: ' + h4); fs.copyFileSync('last_download.jpg','last_unique.jpg'); console.log('After copy...'); var h5 = md5File.sync('last_unique.jpg'); console.log('last_unique.jpg: ' + h5); fs.copyFileSync('last_unique.jpg','file_' + getTimestamp() + '.jpg'); }}request();
Here are the results after 2 runs.
First run:Unique file spotted!last_download.jpg: d6e71956001bc07593fbe2dff2f47978last_unique.jpg: 0d574a85dd8cf9d8178da837635e45b0After copy...last_unique.jpg: d6e71956001bc07593fbe2dff2f47978Second run:Unique file spotted!last_download.jpg: d6e71956001bc07593fbe2dff2f47978last_unique.jpg: 0d574a85dd8cf9d8178da837635e45b0 // this hash is the same again whenever I run itAfter copy...last_unique.jpg: d6e71956001bc07593fbe2dff2f47978
I have a python program that uploads a file using google's resumable upload protocol. The upload works fine, but when I try to follow google's suggestion of requesting metadata for the file after upload in order to compare the server-generated md5hash with the hash I generated during upload, my GET request returns an object metadata json blob with no checksum fields.
I've found a reference in gcs docs that indicates that I have to send some special encryption headers in order to get these server-generated checksum fields to be returned in my metadata GET request, but the docs don't say which headers have to be included - and frankly - I'm not using encryption anyway, so I wouldn't know what headers I should send:
https://cloud.google.com/storage/docs/json_api/v1/objects/get (3rd paragraph)
Interestingly, the google playground (accessible from the link above) allows me to make the object request from their web interface using oauth to access my bucket - I can get this request to return the full object metadata with hash fields. But the playground doesn't indicate the full set of request headers sent (sadly) so I can't even use that to see what I should be sending.
Question: What's the trick to getting google to return the checksum fields when asking for object metadata?
I am working on a C# program that uses md5 hashing. A file is created using an older version of the program and the hash is saved in a field in the file. Here is a code snippet showing the saving of the hash and the file:
using (MD5 md5Hash = MD5.Create()){ this.Hash = string.Empty; s = JsonConvert.SerializeObject(this, Formatting.Indented); string hash = MD5hash.GetMd5Hash(md5Hash, s); this.Hash = hash; s = JsonConvert.SerializeObject(this, Formatting.Indented); }
The string "s" is saved to a file in JSON format and "this" is the object that is serialized.
In a new version of the program I am attempting to load the above file but the md5 hashes don't match even though I compare the files and they are identical. Here is a snippet:
using (MD5 md5Hash = MD5.Create()){ hash = MD5hash.GetMd5Hash(md5Hash, s); if (fhash == hash) { return f; } else { throw new Exception("HashMismatch"); } }
"fhash" is loaded from the file and is the hash that was saved in the older version. Since "s" in the the new version in the above code matches "s" in the older version "hash" and "fhash" should match but they don't. Any suggestions?
Thanks in advance for your help!
Please note that by viewing our site you agree to our use of cookies (see 隐私 for details). You will only see this message once.