topxebec
topxebec

Reputation: 1427

android.utils.Base64.encode gets different value

When I try this:

map.put("password1", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password2", Base64.encode("111111".getBytes(),Base64.DEFAULT));
map.put("password3", Base64.encode("111111".getBytes(),Base64.DEFAULT));

I got different value of password1,password2 and password3:

password1:[B@5368aecc

password2:[B@536e9ea0

password3:[B@536c0dec

Is it should be the same value? Thanks in advance.

Upvotes: 0

Views: 318

Answers (2)

laalto
laalto

Reputation: 152817

You're essentially printing toString() of a byte[] array. The output is different for different byte array objects.

Either don't store the values as byte arrays by removing the .getBytes(), or convert your byte arrays back to string with new String(byteArray, someEncoding).

Upvotes: 1

GAMELASTER
GAMELASTER

Reputation: 1091

Yes, its can be same , when u add a some text to your string, the old part of string is in hashed string same. Check more at Wikipedia

Upvotes: 1

Related Questions