I want to convert a string into hex, then into a byte array. Here is my code so far:
public static void findKey(){
Cipher cipher;
SecretKeySpec key;
byte [] keyBytes;
byte [] pt;
byte [] ct;
String plaintext = "Plaintxt";
ct = new byte [] {(byte)0x4A, (byte)0xC4, (byte)0x55, (byte)0x3D, (byte)0xB3, (byte)0x37, (byte)0xCA, (byte)0xB3};
String ptHex = asciiToHex(plaintext);
System.out.println(ptHex);
pt = ptHex.getBytes();
printByteArray(pt);
}
My method to convert to hex works fine, but when I use getBytes
, it obviously turns it to 16 bytes which is not what I want. That was just an attempt. Here is the output from just printing my string to make sure it worked and then printing the byte array which is incorrect:
506c61696e747874
[ 35 30 36 63 36 31 36 39 36 65 37 34 37 38 37 34 ]
-------------Key Found-------------
I want to take the 50, the 6c, the 61 etc., and put it into a byte array like I did for ct like 0x50, 0x6c, and so on.
Is this even possible?