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 3806684
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:52:22+00:00 2026-05-19T14:52:22+00:00

I have written a util class in Java for webservice call. My util class

  • 0

I have written a util class in Java for webservice call. My util class creates the password digest required for a web service call. This digest password is made up of: A digest password generated with the following algorithm: base64Encode(sha1Hash(<Nonce><TimeStamp><Secret>))

My generated password does not equal to the generated password from the vendor’s tool which uses the same algorithm (I don’t have access to their code so I am not sure how that is implemented). I am not sure if I did something wrong, can someone look over my code and see if I did something wrong with SHA1 encryption or Base64 encoding. Thanks for your help! Below is my code:

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.UUID;

import javax.xml.bind.DatatypeConverter;
import org.apache.commons.codec.binary.Base64;

public class OminitureWSUtil {

private static MessageDigest SHA1;

static {
    try {
        SHA1 = MessageDigest.getInstance("SHA1");

    } catch(NoSuchAlgorithmException nae) {
        throw new RuntimeException(nae);
    }
}

static class OmniturePasswordDigest {
    private final String timestamp;
    private final String nonce;
    private final String secret;

    private String password;

    public OmniturePasswordDigest(String secret) {
        Calendar c = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT+0"));
        c.setTime(new Date());

        //timestamp =  DatatypeConverter.printDateTime(c);
        //nonce = UUID.randomUUID().toString().replace("-", "");

        timestamp = "2011-01-26T20:10:56Z";
        nonce = "MTkyMTYwZWMzMjIzZGJmYzNiYmE5M2E5";

        this.secret = secret;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public String getNonce() {
        return nonce;
    }

    public String generatePassword() {
        if(password == null) {
            String beforeEncryption = nonce+timestamp+secret;
            System.out.println("before encryption, encoding: " + beforeEncryption);

            try {
                SHA1.reset();
                byte[] toEncrypt = beforeEncryption.getBytes("UTF-8");
                //SHA1.update(toEncrypt, 0, toEncrypt.length);
                SHA1.update(beforeEncryption.getBytes());
            } catch (UnsupportedEncodingException uee) {
                throw new RuntimeException(uee);
            }

            byte[] encryptedRaw = SHA1.digest();
            byte[] encoded = Base64.encodeBase64(encryptedRaw);

            try {
                password = new String(encoded, "UTF-8");
            } catch (UnsupportedEncodingException uee) {
                throw new RuntimeException(uee);
            }
        }

        return password;
    }
}


public static OmniturePasswordDigest generatePasswordDigest(String secret) {
    return new OmniturePasswordDigest(secret);
}

public static void main(String[] args) {
    OmniturePasswordDigest opd = generatePasswordDigest("1779ab07fb93a01e3d4a6ee174124b91");
    System.out.println("nonce: " + opd.getNonce());
    System.out.println("timestamp: " + opd.getTimestamp());
    System.out.println("password: " + opd.generatePassword());

    if("Lr+m+/6y3XUxvjd8Rtn75gqn/b4=".equals(opd.generatePassword())) {
        System.out.println("all good");
    } else {
        System.out.println("generated password is not the same, it should be: " + 
                "Lr+m+/6y3XUxvjd8Rtn75gqn/b4=");
    }

}

}

  • 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-19T14:52:23+00:00Added an answer on May 19, 2026 at 2:52 pm

    Race of SHA1 visible from miles away.
    Change the code like that:

    -SHA1.reset();
    +MessageDigest SHA1= (MessageDigest) OminitureWSUtil.SHA1.clone();
    

    Reset is just not what you need; Clone is intended for such cases.

    btw, throwing any exception in the class init (static{}) kills the class and partly any other class referencing that class (so the entire [web]application). It’s a bad practice, since the exception (java.lang.ExceptionInInitializerError) may get trapped somewhere.

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

Sidebar

Related Questions

I have written code in Java to access web cam,and to save image... I
I have written a java class for my class project, and all of my
I have written this class. This is not complete description of original class to
I'm creating a web service in Java that will be consumed by an external
I have written a program in Java to read in a text file of
I have to create a CD inventory program for my first Java class. The
This is what I have so far and I have the problem written as
I have written following code for the client of RMI. But getting java.rmi.ConnectException: Connection
I have written this piece of code: namespace { void SkipWhiteSpace(const char *&s) {
I have written an AIR Application that downloads videos and documents from a server.

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.