I saved this byte array as a string in my database :
public static final byte[] NEW_KEY_2KTDES = {
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff,
(byte)0xff
};
Now I want to get this string from my db and convert it to a byte array (like above). I tried to do it :
String[] str_pass = obj.getString("password").split(" ");
byte[] NEW_KEY = convertToBytes(str_pass);
But that convertToBytes function is the problem :
private static byte[] convertToBytes(String[] strings) {
byte[] data = new byte[strings.length];
for (int i = 0; i < strings.length; i++) {
String string = strings[i];
data[i] = string.getBytes(Charset.defaultCharset()); // you can chose charset
}
return data;
}
Is there a better way ?