javaarraysbase58

Split byte array to get the first 12 chars and the last 12 chars(Java)


I have a byte Array which I want to Base58 encode. But I only want to encode the first 12 and the last 12 letter. So I need to convert the byte array into a String split it and convert it back into a byte array to encode it in Base58? Maybe there is a better way?

Kindly Regards!


Solution

  • You can use Arrays.copyOfRange:

    byte[] first12 = Arrays.copyOfRange(byteArray, 0, 11);
    byte[] last12 = Arrays.copyOfRange(byteArray, byteArray.length - 13, byteArray.length - 1);