(String plainText)
| 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 { |
no test coverage detected