• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File size comparison

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day,

I would like to create a component to detect the file being modify before process.

Seeking for the advice, whether my thought is make sense and is it the right way to detect the file modification based on file size value?

Below are the flow:

1. Get the file size of a file
2. Used file size value encrypt it with MD5 algorithm, and say it generated us encrypted value "0123sdf"
3. to avoid user modify the file content, before file process, we take the file and do the encryption with md5 again, if it return value "0123sdf", then we are sure it doesn't have modification.

my question:
a. is it the right approach to detect file modification?
b. what the library advise to use or using java.security.DigestInputStream will do?

Thanks for enlighten!
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO using file size as the only indicator for "file changed status" is rather vague. The file size may be the same yet the content is changed (eg a letter)

I suggest using the last modified date/time.

Also you should consider what happens when your program is doing whatever to the file (in memory perhaps) that no one tampers it in between. In another word, can the file be locked (similar to database row or table locking) during processing?

 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks K. Tsang, that's sound a better idea on using modified date !

Between, After the file generation, it will drop into a unix folder and then move into DB, it suppose not interfere by the user, management want to ensure security.

regards the implementation, if possible could you please shed some light on this too ?

 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First how is the file uploaded to the server? FTP, web UI upload etc? If FTP, do end users have direct access to the FTP folder through FTP client software or something?

Suppose it's web UI upload. Given user A and user B has the same file name called "Y2014budget.txt". Both user A and user B made some changes independent of each other. They upload their respective file through the web interface.

In normal situation, whoever upload last will overwrite the previous uploads..... I doubt you want that!

Under this situation, the "uploaded" file name would have to be changed, say appending a unique key (eg db PK) at the end or something to say Y2014budget.txt_1

This advantage to this approach is uploaded files never get overwritten. Disadvantage, use more disk space.

Depending on whether the files have any defined spec having header, footer, etc. If so, the file renaming may need to corresponding to those "file name" entries inside the file (usually in header and/or footer)
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the last modified date/time is not at all safe. It is very easy to modify a file and set it's modified time back the original file's time.
 
Nakataa Kokuyo
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi K. Tsang,

there are two ways user can trigger the file generation - manual or auto.

Both approach will trigger from web UI, for manual, user can download the file and allow to upload it into different environment at anytime.
for auto, user trigger the file generation process from web UI and the generated file will transfer over via FTP to other environment instantly.

the file size checksum is to ensure the content is not being modify by the user.

 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic