(PBKDF2) Hash created differently each times for

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

(PBKDF2) Hash created differently each times for

Bruce
Assuming plainText is a variable containing the plain password, I have tried to create a hash using "Password-based Key Derivation Function 2 (PBKDF2)". After some online research, I got the below codes. However when running the below codes multiple times, I observe that the hash generated  each time is different, for the same password and same text.  So would like to ask if this is normal?  Thanks.

PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();

generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(plainText.toCharArray()),"salt".getBytes("UTF-8"),1000);

KeyParameter params=(KeyParameter)generator.generateDerivedMacParameters(128);

System.out.println(params.getKey().toString());
Reply | Threaded
Open this post in threaded view
|

Re: (PBKDF2) Hash created differently each times for

Bruce
Sorry, correct some typo

Assuming plainText is a variable containing the plain password, I have tried to create a hash using "Password-based Key Derivation Function 2 (PBKDF2)". After some online research, I got the below codes. However when running the below codes multiple times, I observe that the hash generated  each time is different, for the same password and same salt.  So would like to ask if this is normal?  Thanks.

PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();

generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(plainText.toCharArray()),"salt".getBytes("UTF-8"),1000);

KeyParameter params=(KeyParameter)generator.generateDerivedMacParameters(128);

System.out.println(params.getKey().toString());

On Thu, Apr 19, 2018 at 10:07 AM, Bruce <[hidden email]> wrote:
Assuming plainText is a variable containing the plain password, I have tried to create a hash using "Password-based Key Derivation Function 2 (PBKDF2)". After some online research, I got the below codes. However when running the below codes multiple times, I observe that the hash generated  each time is different, for the same password and same text.  So would like to ask if this is normal?  Thanks.

PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();

generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(plainText.toCharArray()),"salt".getBytes("UTF-8"),1000);

KeyParameter params=(KeyParameter)generator.generateDerivedMacParameters(128);

System.out.println(params.getKey().toString());

Reply | Threaded
Open this post in threaded view
|

Re: (PBKDF2) Hash created differently each times for

David Hook-3

getKey() returns a byte[] - try Hex.toHexString(params.getKey())

Regards,

David

On 19/04/18 12:12, Bruce wrote:
Sorry, correct some typo

Assuming plainText is a variable containing the plain password, I have tried to create a hash using "Password-based Key Derivation Function 2 (PBKDF2)". After some online research, I got the below codes. However when running the below codes multiple times, I observe that the hash generated  each time is different, for the same password and same salt.  So would like to ask if this is normal?  Thanks.

PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();

generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(plainText.toCharArray()),"salt".getBytes("UTF-8"),1000);

KeyParameter params=(KeyParameter)generator.generateDerivedMacParameters(128);

System.out.println(params.getKey().toString());

On Thu, Apr 19, 2018 at 10:07 AM, Bruce <[hidden email]> wrote:
Assuming plainText is a variable containing the plain password, I have tried to create a hash using "Password-based Key Derivation Function 2 (PBKDF2)". After some online research, I got the below codes. However when running the below codes multiple times, I observe that the hash generated  each time is different, for the same password and same text.  So would like to ask if this is normal?  Thanks.

PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();

generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(plainText.toCharArray()),"salt".getBytes("UTF-8"),1000);

KeyParameter params=(KeyParameter)generator.generateDerivedMacParameters(128);

System.out.println(params.getKey().toString());