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

  • Home
  • SEARCH
  • 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 7599913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:46:40+00:00 2026-05-30T22:46:40+00:00

I have found the following example code (somewhere on the web, can’t remember where):

  • 0

I have found the following example code (somewhere on the web, can’t remember where):

public static byte[] produce(final byte[] data)
        throws NoSuchAlgorithmException{
    MessageDigest digest = MessageDigest.getInstance(ALGORITHM);
    digest.reset();
    digest.update(data);
    byte[] ret = digest.digest(data);
    for (int i = 0; i < HASH_ITERATIONS; i++) {
        digest.reset();
        ret = digest.digest(ret);
    }
    return ret;
}

What bothers me is that the docs says that digest() already calls update() on its own with the passed input:

Performs a final update on the digest using the specified array of
bytes, then completes the digest computation. That is, this method
first calls update(input), passing the input array to the update
method, then calls digest().

Additionally, after the call to update(), the MessageDigest object’s state becomes 1.
After a call to digest() (next in the code) it returns to be simply 0.
Finally, when stepping through while debugging, I can clearly see that the data is being manipulated.

So, is it safe to remove the call to update()?

Note that I wouldn’t bother anyone with that question if it weren’t a big security issue.

  • 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-30T22:46:42+00:00Added an answer on May 30, 2026 at 10:46 pm

    You are right, it is safe to remove update in your code. And more, by calling update(data) and then calling digest(data) you actually calculating digest of different message that contains data twice. I think is not what you need.

    The common use case of digest(byte[]) is calculation of digest of complete data block (i.e. password). The update(byte[]) in pair with digest() used when you need to calculate digest of data coming by parts:

    int read = 0; 
    while ((read = fis.read(buffer)) != -1) {
        md.update(buffer, 0, read);
    };
    byte[] digest  = md.digest();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found the following code example for Java on RosettaCode : public static boolean
According to what I have found so far, I can use the following code:
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I am trying to run the following recognizer intent example that i have found
I have found some very useful code: RewriteEngine On RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule
I have found the following command in AWK useful in Vim :'<,'>!awk '{ print
I have found the following expression which is intended to modify the id of
I have found the following resources on Balanced Matching for .net Regexes: http://weblogs.asp.net/whaggard/archive/2005/02/20/377025.aspx http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx
Reading a book I have found the following statement: (Object) Behaviors answer either of
Searching online, I have found the following routine for calculating the sign of a

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.