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

Method encodeString

java/src/cx/fbn/encrypt/EnCrypt.java:84–111  ·  view source on GitHub ↗
(String text, int length)

Source from the content-addressed store, hash-verified

82 * 2. Use specific named charset
83 */
84 private byte[] encodeString(String text, int length) {
85
86 final Charset charSet = getCharset();
87
88 // Convert to bytes using given encoding, and align *bytes* to multiple of
89 // 8, with 4 bytes reserved for the crc
90 final byte[] bytes = text.getBytes(charSet);
91 int align = (bytes.length + 4) % length;
92 int paddingNeeded = length - align;
93 final byte[] paddedBytes = Arrays.copyOf(bytes, bytes.length + paddingNeeded);
94
95 // Now calculate the crc, using the bytes
96 String crc = crcHeader(paddedBytes);
97
98 byte[] crcBytes = crc.getBytes(charSet);
99 if(crcBytes.length != 4) {
100 System.err.println("CRC Bytes really should be 4 in length!");
101 return null;
102 }
103
104 // Now combine crc bytes and string bytes into byte array
105 // for encryption
106 byte[] total = new byte[paddedBytes.length + crcBytes.length];
107 System.arraycopy(crcBytes, 0, total, 0, crcBytes.length);
108 System.arraycopy(paddedBytes, 0, total, crcBytes.length, paddedBytes.length);
109
110 return total;
111 }
112
113
114 /**

Callers 2

encryptRC2Method · 0.95
encryptAESMethod · 0.95

Calls 2

getCharsetMethod · 0.95
crcHeaderMethod · 0.95

Tested by

no test coverage detected