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

Method encryptData_CBC

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

Source from the content-addressed store, hash-verified

85 }
86
87 public String encryptData_CBC(String plainText) {
88 try {
89 SM4_Context ctx = new SM4_Context();
90 ctx.isPadding = true;
91 ctx.mode = SM4.SM4_ENCRYPT;
92
93 byte[] keyBytes;
94 byte[] ivBytes;
95 if (hexString) {
96 keyBytes = Util.hexStringToBytes(secretKey);
97 ivBytes = Util.hexStringToBytes(iv);
98 } else {
99 keyBytes = secretKey.getBytes();
100 ivBytes = iv.getBytes();
101 }
102
103 SM4 sm4 = new SM4();
104 sm4.sm4_setkey_enc(ctx, keyBytes);
105 byte[] encrypted = sm4.sm4_crypt_cbc(ctx, ivBytes, plainText.getBytes("UTF-8"));
106 return Util.byteToHex(encrypted);
107 } catch (Exception e) {
108 e.printStackTrace();
109 return null;
110 }
111 }
112
113 public String decryptData_CBC(String cipherText) {
114 try {

Callers 2

mainMethod · 0.95
encryptKeyivmodeMethod · 0.95

Calls 4

hexStringToBytesMethod · 0.95
sm4_setkey_encMethod · 0.95
sm4_crypt_cbcMethod · 0.95
byteToHexMethod · 0.95

Tested by

no test coverage detected