MCPcopy Index your code
hub / github.com/f0ng/autoDecoder / sm4_crypt_ecb

Method sm4_crypt_ecb

src/com/autoDecoder/util/SM4.java:243–270  ·  view source on GitHub ↗
(SM4_Context ctx, byte[] input)

Source from the content-addressed store, hash-verified

241 }
242
243 public byte[] sm4_crypt_ecb(SM4_Context ctx, byte[] input) throws Exception {
244 if (input == null) {
245 throw new Exception("input is null!");
246 }
247
248 if ((ctx.isPadding) && (ctx.mode == SM4_ENCRYPT)) {
249 input = padding(input, SM4_ENCRYPT);
250 }
251
252 int length = input.length;
253 ByteArrayInputStream bins = new ByteArrayInputStream(input);
254 ByteArrayOutputStream bous = new ByteArrayOutputStream();
255 for (; length > 0; length -= 16) {
256 byte[] in = new byte[16];
257 byte[] out = new byte[16];
258 bins.read(in);
259 sm4_one_round(ctx.sk, in, out);
260 bous.write(out);
261 }
262
263 byte[] output = bous.toByteArray();
264 if (ctx.isPadding && ctx.mode == SM4_DECRYPT) {
265 output = padding(output, SM4_DECRYPT);
266 }
267 bins.close();
268 bous.close();
269 return output;
270 }
271
272 public byte[] sm4_crypt_cbc(SM4_Context ctx, byte[] iv, byte[] input) throws Exception {
273 if (iv == null || iv.length != 16) {

Callers 2

encryptData_ECBMethod · 0.95
decryptData_ECBMethod · 0.95

Calls 2

paddingMethod · 0.95
sm4_one_roundMethod · 0.95

Tested by

no test coverage detected