MCPcopy Create free account
hub / github.com/TrsstProject/trsst / process

Method process

src/main/java/com/trsst/Crypto.java:130–163  ·  view source on GitHub ↗
(byte[] input,
            BufferedBlockCipher bufferedBlockCipher,
            CipherParameters cipherParameters, boolean forEncryption)

Source from the content-addressed store, hash-verified

128
129 // h/t Adam Paynter http://stackoverflow.com/users/41619/
130 private static byte[] process(byte[] input,
131 BufferedBlockCipher bufferedBlockCipher,
132 CipherParameters cipherParameters, boolean forEncryption)
133 throws InvalidCipherTextException {
134 bufferedBlockCipher.init(forEncryption, cipherParameters);
135
136 int inputOffset = 0;
137 int inputLength = input.length;
138
139 int maximumOutputLength = bufferedBlockCipher
140 .getOutputSize(inputLength);
141 byte[] output = new byte[maximumOutputLength];
142 int outputOffset = 0;
143 int outputLength = 0;
144
145 int bytesProcessed;
146
147 bytesProcessed = bufferedBlockCipher.processBytes(input, inputOffset,
148 inputLength, output, outputOffset);
149 outputOffset += bytesProcessed;
150 outputLength += bytesProcessed;
151
152 bytesProcessed = bufferedBlockCipher.doFinal(output, outputOffset);
153 outputOffset += bytesProcessed;
154 outputLength += bytesProcessed;
155
156 if (outputLength == output.length) {
157 return output;
158 } else {
159 byte[] truncatedOutput = new byte[outputLength];
160 System.arraycopy(output, 0, truncatedOutput, 0, outputLength);
161 return truncatedOutput;
162 }
163 }
164
165 /**
166 * Computes hashcash proof-of-work stamp for the given input and

Callers 1

_cryptBytesAESMethod · 0.95

Calls 1

initMethod · 0.80

Tested by

no test coverage detected