MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / decodeBytes

Method decodeBytes

java/src/cx/fbn/encrypt/EnCrypt.java:119–143  ·  view source on GitHub ↗

Same as for encryption: use named charset, and @param bytes @return

(byte[] bytes)

Source from the content-addressed store, hash-verified

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

Callers 2

decryptRC2Method · 0.95
decryptAESMethod · 0.95

Calls 6

getCharsetMethod · 0.95
crcHeaderMethod · 0.95
decodeMethod · 0.45
wrapMethod · 0.45
toStringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected