简体   繁体   English

如何识别上传的excel文件是否与下载的相同?

[英]How to identify if uploaded excel file is same as that is downloaded?

I am developing excel download & upload functionality using Java.我正在使用 Java 开发 excel 下载和上传功能。

I have a link on my screen through which, user will download an excel.我的屏幕上有一个链接,用户可以通过它下载一个 excel。

I provide functionality to upload the excel.我提供上传excel的功能。 But, while uploading, I want restrict user to upload only that excel file which is downloaded to maintain security.但是,在上传时,我想限制用户只上传为维护安全而下载的 excel 文件。

How will I be able to do that ?我将如何能够做到这一点?

I am using JXL API for Java.我正在为 Java 使用 JXL API。

EDIT: User will download the file, which will have all protected cells.编辑:用户将下载该文件,该文件将包含所有受保护的单元格。

User will change the details in it and then re-upload it.用户将更改其中的详细信息,然后重新上传。

User may copy the content of the excel and save in another excel file and then add some junk data in it which may come across some security concerns.用户可以复制excel的内容并保存在另一个excel文件中,然后在其中添加一些垃圾数据,这可能会遇到一些安全问题。

To avoid it while uploading the file, I want to identify if the file is same as that is downloaded.为了在上传文件时避免它,我想确定文件是否与下载的文件相同。

An idea would be to add an unique ID somewhere inside the file and lock those cells from editing.一个想法是在文件内的某处添加一个唯一 ID 并锁定这些单元格以防止编辑。

You could check this tutorial on how to Lock or unlock specific areas of a protected worksheet您可以查看本教程,了解如何锁定或解锁受保护工作表的特定区域

Also, you can compare the files' creation date timestamps and check if they're the same.此外,您可以比较文件的创建日期时间戳并检查它们是否相同。

It is not possible to do what you want.做你想做的事是不可能的。 The user will have access to everything you give them.用户将有权访问您提供给他们的所有内容。 If they are attacking you, they can use that to spoof that the file is the same.如果他们正在攻击您,他们可以使用它来欺骗文件是相同的。 You need to do data validation on what comes in from the user, just like any other time you ask the user for data.您需要对来自用户的内容进行数据验证,就像您向用户询问数据的任何其他时间一样。

Probably the closest you can get is to check that every locked cell is still locked with the same password.可能最接近的是检查每个锁定的单元格是否仍然使用相同的密码锁定。 There's still no guarantee that they haven't hacked your password, though, and once you're looking at every cell anyway, you may as well validate the value instead of the lock.但是,仍然不能保证他们没有破解您的密码,而且一旦您查看了每个单元格,您也可以验证值而不是锁。

  1. Protect sheet( or required cells) with a password.使用密码保护工作表(或所需的单元格)。
  2. On upload verify the password.上传时验证密码。
  3. Store the password in property files or in some secured location.将密码存储在属性文件或某个安全位置。

I have resolved my issue using Apache POI lib and "validateSheetPassword(pwd)" method.我已经使用 Apache POI lib 和“validateSheetPassword(pwd)”方法解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM