JPasswordField, charset and char[] to byte[]

K

Kai Schlamp

Hy!

I have to convert a char[] from JPasswordField to byte[] (to use for AES encryption with JCE).
What charset does the given back char[] use (cause I want to stay platform independent)? UTF-16
(cause of the 2 bytes), or something like that?
If I use the following algrorithm, does Java give me the same byteArray on every platform?
Especially some special characters have some complete different hexcodes in different charsets (like
the Euro symbol), and if Java internally uses the default charset of the system, then I get
different byteArrays on different platforms. Or does Java use an own charset internally?

Here my algorithm:

byte[] convert(char[] pass) {
byte[] byteArray = new byte [charArray.length*2];
for (int i=0; i < charArray.length; i++) {
byteArray[i*2]=(byte) (charArray>>8);
byteArray[i*2+1] = (byte) charArray;
}
return byteArray;
}

Thanks in advance,
Kai
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top