Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Karl.Frank" <Karl.Frank@Freecx.co.uk> |
|---|---|
| Newsgroups | sci.crypt |
| Subject | Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? |
| Date | 2018-05-15 18:31 +0200 |
| Organization | albasani.net |
| Message-ID | <pdf20e$pos$1@news.albasani.net> (permalink) |
| References | <pdf0kv$uom$1@news.albasani.net> |
On 15.05.18 18:07, Karl.Frank wrote:
> I've stuck with getting potential wrong results from a Java 7
> implementation.
>
> If I call a test function like
>
> echo -n "Lsda[¥~§#€]" | java -jar pbkdf2_stdin.jar "Salt" 4096 16 sha-1
>
> I get
>
> Password : 4c7364615bc2a57ec2a723e282ac5d
> Salt : 53616c74
> PBKDF2 : aba223d6679ad1e8101c01bf860f788b
> PBKDF2_java: 461f05924a7945a652bcabb30d87fad3
>
> whereupon PBKDF2 is the result given be my own PBKDF2 implementation and
> PBKDF2_java what I get using the javax library.
>
> So I'm wondering if converting the Password into a char array instead of
> a byte array might be the correct approach.
>
> Verified the PBKDF2 result at
> https://asecuritysite.com/encryption/PBKDF2z and I get:
> aba223d6679ad1e8101c01bf860f788b
>
> Can anyone give me a hint on this matter?
>
>
>
>
I suppose it might be necessary to explain how I call the functions.
---------8<-----------------------------------------
basicFunctions bf = new basicFunctions();
cryptoFunctions cf = new cryptoFunctions();
if (System.in.available() > 0) {
String hashType, PBKDF2_Result, Password, Salt;
int dkLen, c;
int BuffSize = System.in.available();
byte[] pwByte = new byte[BuffSize];
System.in.read(pwByte, 0, BuffSize);
Password = bf.byteArrToString(pwByte);
Salt = argv[0];
c = Integer.parseInt(argv[1]);
dkLen = Integer.parseInt(argv[2]);
hashType = argv[3];
System.err.println("Password : " +
bf.byteArrToHexString(Password.getBytes()));
System.err.println("Salt : " +
bf.byteArrToHexString(Salt.getBytes()));
PBKDF2_Result = bf.byteArrToHexString( cf.PBKDF2(hashType,
Password.getBytes(), Salt.getBytes(), c, dkLen) );
System.err.println("PBKDF2 : " + PBKDF2_Result);
PBKDF2_Result = bf.byteArrToHexString( pbkdf2_javax(hashType,
Password, Salt, c, dkLen) );
System.err.println("PBKDF2_java: " + PBKDF2_Result);
}
else {
System.err.printf("Pass data via stdin.\n");
}
--------->8-----------------------------------------
Inhere the password is read from stdin into a byte array (pwByte), then
converted into a string (Password), because the javax PBKDF2 function
does not accept a byte array for the password parameter, whereas it does
for the salt.
My own PBKDF2 implementation however is only accepting byte arrays for
password and salt, because I prefer staying on the byte level in regards
of cryptography.
bf.byteArrToString(), bf.byteArrToHexString() and cf.PBKDF2 are some
functions of my own functions lib that simply do as they are named.
In addtion this is the PBKDF2 function of javax
---------8<-----------------------------------------
public static byte[] pbkdf2_javax(String hashType, String password,
String salt, int iterations, int dkLen) {
byte[] derivedKey = new byte[dkLen];
if ( Integer.parseInt(hashType.substring(4)) > 1 ) return derivedKey;
try {
SecretKeyFactory f =
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec ks = new PBEKeySpec(password.toCharArray(),
salt.getBytes(), iterations, dkLen*8);
SecretKey s = f.generateSecret(ks);
derivedKey = s.getEncoded();
}
catch (Exception e) {
e.printStackTrace();
}
return derivedKey;
}
--------->8-----------------------------------------
For example calling the test program like below does give the correct
result for both functions output.
echo -n "The quick brown fox jumps over the lazy dog" | java -jar
pbkdf2_stdin.jar "Salt" 4096 16 sha-1
PBKDF2 : cf93699a512044c1bc788699cc986f88
PBKDF2_java: cf93699a512044c1bc788699cc986f88
--
cHNiMUBACG0HAAAAAAAAAAAAAABIZVbDdKVM0w1kM9vxQHw+bkLxsY/Z0czY0uv8/Ks6WULxJVua
zjvpoYvtEwDVhP7RGTCBVlzZ+VBWPHg5rqmKWvtzsuVmMSDxAIS6Db6YhtzT+RStzoG9ForBcG8k
G97Q3Jml/aBun8Kyf+XOBHpl5gNW4YqhiM0=
Back to sci.crypt | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 18:07 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 18:31 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Bruce Stephens <bruce.r.stephens@gmail.com> - 2018-05-15 19:46 +0100
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 20:52 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Rich <rich@example.invalid> - 2018-05-15 18:49 +0000
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 21:02 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? wizzofozz <oscxxxxxxxaas@gmail.com> - 2018-05-15 21:09 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? wizzofozz <oscxxxxxxxaas@gmail.com> - 2018-05-15 21:11 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 21:25 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 21:29 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? wizzofozz <oscxxxxxxxaas@gmail.com> - 2018-05-15 22:07 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Rich <rich@example.invalid> - 2018-05-15 20:38 +0000
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 22:57 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 21:42 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-15 23:37 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-05-16 15:58 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Robert Klemme <shortcutter@googlemail.com> - 2018-06-18 18:41 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-06-18 13:33 -0700
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-06-19 12:54 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Lothar Kimmeringer <news201705@kimmeringer.de> - 2018-06-19 22:18 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Robert Klemme <shortcutter@googlemail.com> - 2018-06-19 23:20 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-06-19 23:23 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? Robert Klemme <shortcutter@googlemail.com> - 2018-06-19 23:15 +0200
Re: Why is Java 7 converting the Password toCharArray instead of Byte in it's PBKDF2 function? "Karl.Frank" <Karl.Frank@Freecx.co.uk> - 2018-06-20 00:03 +0200
csiph-web