(String cipherText)
| 50 | } |
| 51 | |
| 52 | public String decryptData_ECB(String cipherText) { |
| 53 | try { |
| 54 | byte[] encrypted = Util.hexToByte(cipherText); |
| 55 | cipherText=Base64.encodeBase64String(encrypted);; |
| 56 | //cipherText = new BASE64Encoder().encode(encrypted); |
| 57 | if (cipherText != null && cipherText.trim().length() > 0) { |
| 58 | Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
| 59 | Matcher m = p.matcher(cipherText); |
| 60 | cipherText = m.replaceAll(""); |
| 61 | } |
| 62 | System.out.println(secretKey); |
| 63 | |
| 64 | SM4_Context ctx = new SM4_Context(); |
| 65 | ctx.isPadding = true; |
| 66 | ctx.mode = SM4.SM4_DECRYPT; |
| 67 | |
| 68 | byte[] keyBytes; |
| 69 | if (hexString) { |
| 70 | keyBytes = Util.hexStringToBytes(secretKey); |
| 71 | } else { |
| 72 | keyBytes = secretKey.getBytes(); |
| 73 | } |
| 74 | |
| 75 | SM4 sm4 = new SM4(); |
| 76 | sm4.sm4_setkey_dec(ctx, keyBytes); |
| 77 | System.out.println("SM4Utils 77 " + cipherText); |
| 78 | byte[] decrypted = sm4.sm4_crypt_ecb(ctx, Base64.decodeBase64(cipherText)); |
| 79 | //byte[] decrypted = sm4.sm4_crypt_ecb(ctx, new BASE64Decoder().decodeBuffer(cipherText)); |
| 80 | return new String(decrypted, "UTF-8"); |
| 81 | } catch (Exception e) { |
| 82 | // e.printStackTrace(); |
| 83 | return null; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | public String encryptData_CBC(String plainText) { |
| 88 | try { |
no test coverage detected