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

Method encryptData_ECB

src/com/autoDecoder/util/SM4Utils.java:28–50  ·  view source on GitHub ↗
(String plainText)

Source from the content-addressed store, hash-verified

26
27
28 public String encryptData_ECB(String plainText) {
29 try {
30 SM4_Context ctx = new SM4_Context();
31 ctx.isPadding = true;
32 ctx.mode = SM4.SM4_ENCRYPT;
33
34 byte[] keyBytes;
35 if (hexString) {
36 keyBytes = Util.hexStringToBytes(secretKey);
37 } else {
38 keyBytes = Util.hexStringToBytes(secretKey);
39 }
40
41 SM4 sm4 = new SM4();
42 sm4.sm4_setkey_enc(ctx, keyBytes);
43 byte[] encrypted = sm4.sm4_crypt_ecb(ctx, plainText.getBytes("UTF-8"));
44 System.out.println("SM4Utils 44 " + Util.byteToHex(encrypted));
45 return Util.byteToHex(encrypted);
46 } catch (Exception e) {
47 e.printStackTrace();
48 return null;
49 }
50 }
51
52 public String decryptData_ECB(String cipherText) {
53 try {

Callers 1

encryptKeyivmodeMethod · 0.95

Calls 4

hexStringToBytesMethod · 0.95
sm4_setkey_encMethod · 0.95
sm4_crypt_ecbMethod · 0.95
byteToHexMethod · 0.95

Tested by

no test coverage detected