Same as for encryption: use named charset, and @param bytes @return
(byte[] bytes)
| 117 | * @return |
| 118 | */ |
| 119 | private String decodeBytes(byte[] bytes) { |
| 120 | |
| 121 | Charset charSet = getCharset(); |
| 122 | |
| 123 | byte[] crcBytes = Arrays.copyOfRange(bytes, 0, 4); |
| 124 | byte[] textBytes = Arrays.copyOfRange(bytes, 4, bytes.length); |
| 125 | |
| 126 | CharBuffer crcChar = charSet.decode(ByteBuffer.wrap(crcBytes)); |
| 127 | CharBuffer textChar = charSet.decode(ByteBuffer.wrap(textBytes)); |
| 128 | |
| 129 | // Get crc of text to see if same |
| 130 | String cryptCRC = crcChar.toString(); |
| 131 | String realCRC = crcHeader(textBytes); |
| 132 | |
| 133 | if(realCRC.equals(cryptCRC)) { |
| 134 | // Trim nulls at end |
| 135 | while(textChar.get(textChar.limit() - 1) == 0 && textChar.limit() != 0) { |
| 136 | textChar.limit(textChar.limit() - 1); |
| 137 | } |
| 138 | String str = textChar.toString(); |
| 139 | return str; |
| 140 | } |
| 141 | |
| 142 | return ""; |
| 143 | } |
| 144 | |
| 145 | |
| 146 |