Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:58:09+00:00 2026-05-23T00:58:09+00:00

I need to verify a signed jar from my application. I found I can

  • 0

I need to verify a signed jar from my application. I found I can do it by reading all contents, like this:

public boolean verifyJar(String filePath) {
    try {
        JarFile jar = new JarFile(filePath, true);
        Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            InputStream is = jar.getInputStream(entry);
            byte[] buffer = new byte[10000];
            while (is.read(buffer, 0, buffer.length) != -1) {
                // we just read. this will throw a SecurityException
                // if a signature/digest check fails.
            }
            is.close();
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

If I execute the checker with a valid jar, it passes. If I corrupt the jar by cutting it in half, it fails. But if I do both in one process, the second check passes (as if it read the previous version of the file)!

public static void main(String[] args) throws Exception {
    String path = "src/test/resources/temp/lib.jar";
    // Passes - that's good
    System.out.println(new Validator().verifyJar(path));

    byte[] content = FileUtil.readFile(path);
    FileUtil.save(path, Arrays.copyOf(content, content.length / 2));
    // Passes - but it shouldn't.
    // Fails if the first check is commented out though.
    System.out.println(new Validator().verifyJar(path));
}

So it looks like ZipFile or JarFile is cached somehow. How do I suppress this behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:58:09+00:00Added an answer on May 23, 2026 at 12:58 am

    ZipFile has to be closed in order native code not to cache. Iirc ZipFile wraps the same handle (jzfile) if the path and File.lastModified are the same.

    Alternatively touching File.lastModified may do the trick too but closing anything open manually (incl. ZipFile) is necessary to prevent resource leaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody verify this method. I need a long type number inside a range
In my application I need to verify whether it's signed or not. If it's
I need to verify if the args are valid file names, is this the
I have a self-signed JAR file. I would like for it to be able
I have some signed .ps1 script, I need to verify they are properly signed
I'm using the following code to verify the application is signed. It's in Objective-C
Need to verify that the attribute can be applied only to a class that
I need to verify input which is like en-US or en-us or ar-AE I
I need to verify the correct function of an application I am working with,
I am developing an ASP.Net application that will need to verify that the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.