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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:03:21+00:00 2026-06-13T09:03:21+00:00

I have am trying to use PBKDF2 to store passwords. I am then using

  • 0

I have am trying to use PBKDF2 to store passwords. I am then using the code with the password hashes it generated on a different machine.

I am using this method to encrypt my passwords:

public  String pwdEncodePBKDF2(String unencryptedPassword,String salt)
{
try
{
        if(salt.isEmpty())
        {
            salt = generateSalt(SystemSecurity.SALTLENGTH);
        }
        String algorithm = "PBKDF2WithHmacSHA1";
        int derivedKeyLength = 160;
        int iterations = 1000;
        KeySpec spec = new PBEKeySpec(unencryptedPassword.toCharArray(), salt.getBytes(), iterations, derivedKeyLength);
        SecretKeyFactory f = SecretKeyFactory.getInstance(algorithm);
        StringBuffer hexString = new StringBuffer();
        byte[] mdbytes  =  f.generateSecret(spec).getEncoded();
        for (int i=0;i<mdbytes.length;i++)
        {
            hexString.append(Integer.toHexString(0xFF & mdbytes[i]));
        }
        String hashedPassword = hexString.toString();
        return hashedPassword  + salt;
    }
    catch(Exception e)
    {
        e.printStackTrace();
        throw new RuntimeException("Error computing hash: "+e.getMessage());
    }        
}

It works fine, but when I run it on a different machine (i.e. install my project on a different machine, with a database that has an encrypted of a default password from the machine I run on initially)
I see that with the same salt and password it give me a different encryption.
As far as I understand the SecretKeyFactory methods depend only on the inputs I give them, or do they depend on the machine I am running on as well?

If so, how can I save a default password for first installation with this security mechanism without running any extra code during installation?

Thank You!

  • 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-06-13T09:03:22+00:00Added an answer on June 13, 2026 at 9:03 am

    I think the problem may be in different default String encodings.

    Check that your strings use same encoding.

    you can try to check bytes using

    salt.getBytes()
    
    • it return bytes in default encoding, may be machines has different encodings.

    You can just replace salt.getBytes(), with somethink like salt.getBytes(“UTF-8”); may be it will help.

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

Sidebar

Related Questions

I have been trying to use the hibernate dialect for SQLite from http://code.google.com/p/hibernate-sqlite/ in
I have been trying to use JSON to store settings for a program. I
I'm trying to use CommonCrypto to generate keys using PBKDF2 but I can't seem
I have been trying to use localstorage to store Jquery-min but I am unable
So I have trouble trying to use any of these two elements for different
I have been trying to use the same HttpClient instance throughout different activities, but
I have been trying to use the raw socket in my machine under windows
I have been trying to use macport's installation by using sudo port install emacs
I have been trying to use this inside an ajax function to refer the
Hi All I have trying to use this http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3fundamentals_topic8.aspx , but i have some

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.