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
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