Skip to content

Commit

Permalink
Merge pull request #290 from DSheirer/289-shoutcast-2-credentials-enc…
Browse files Browse the repository at this point in the history
…ryption-error

289 Shoutcast 2 Login Error
  • Loading branch information
DSheirer committed Nov 23, 2017
2 parents 88580af + 1ddc0a3 commit 1b42e64
Showing 1 changed file with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,48 @@ public void setCredentials(String encryptionKey, int streamID, String userID, St
}

/**
* Encrypts the value using the XTEA block cipher algorithm and returns the encrypted value as a 16 hex value
* Encrypts the value using the XTEA block cipher algorithm. The byte array is sliced into 8-byte chunks and each
* chunk is encrypted into a 16 hexadecimal character string. All encrypted chunks are concatenated and returned
* as a single string. If the value byte array is not an even multiple of 8 characters, it will be padded with
* zero valued bytes to make it an even multiple of eight.
*
* @param xtea instance of the XTEA algorithm with a loaded encryption key
* @param value to encode
* @return encrypted password as 64-bit, 16 character hexadecimal value
* @return value encrypted into one or more multiples of 16 hexadecimal characters
*/
private static String encrypt(XTEA xtea, String value)
private static String encrypt(XTEA xtea, byte[] value)
{
byte[] valueBytes = value.getBytes();

if(valueBytes.length % 8 != 0 || valueBytes.length == 0)
if(value.length % 8 != 0 || value.length == 0)
{
int newLength = ((valueBytes.length / 8) + 1) * 8;
valueBytes = Arrays.copyOf(valueBytes, newLength);
int newLength = ((value.length / 8) + 1) * 8;
value = Arrays.copyOf(value, newLength);
}

byte[] encrypted = xtea.encrypt(valueBytes);

StringBuilder sb = new StringBuilder();

for(byte b: encrypted)
for(int x = 0; x < value.length; x += 8)
{
sb.append(String.format("%02x", b));
byte[] plaintext = Arrays.copyOfRange(value, x, x + 8);
byte[] encrypted = xtea.encrypt(plaintext);

for(byte b: encrypted)
{
sb.append(String.format("%02x", b));
}
}

return sb.toString();
}

/**
* Encrypts the value using the XTEA block cipher algorithm and returns the encrypted value as a 16 hex value
*
* @param xtea instance of the XTEA algorithm with a loaded encryption key
* @param value to encode
* @return encrypted password as 64-bit, 16 character hexadecimal value
*/
private static String encrypt(XTEA xtea, String value)
{
return encrypt(xtea, value.getBytes());
}
}

0 comments on commit 1b42e64

Please sign in to comment.