| | |
| | | * @param data 需要解密的数据 |
| | | * @param aesKey 秘钥 |
| | | * @param encoding 编码,不填默认UTF-8 |
| | | * @return |
| | | * @throws Exception |
| | | * @return 解密数据 |
| | | */ |
| | | public static String decrpt(String data,String aesKey,String encoding) throws Exception { |
| | | public static String decryptData(String data,String aesKey,String encoding) { |
| | | try{ |
| | | if(StringUtils.isEmpty(encoding)){ |
| | | encoding = "UTF-8"; |
| | | } |
| | | // Decrypt |
| | | final Cipher decryptCipher = Cipher.getInstance("AES"); |
| | | decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(aesKey, encoding)); |
| | | return new String(decryptCipher.doFinal(Hex.decodeHex(data.toCharArray()))); |
| | | data = new String(decryptCipher.doFinal(Hex.decodeHex(data.toCharArray()))); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | /**AES加密 |
| | |
| | | * @param aesKey 秘钥 |
| | | * @param encoding 编码,不填默认UTF-8 |
| | | * @return 返回大写加密的数据 |
| | | * @throws Exception |
| | | */ |
| | | public static String encrpt(String data,String aesKey,String encoding) throws Exception { |
| | | public static String encryptData(String data,String aesKey,String encoding) { |
| | | try { |
| | | if(StringUtils.isEmpty(encoding)){ |
| | | encoding = "UTF-8"; |
| | | } |
| | |
| | | for (char d : code) { |
| | | builder.append(d); |
| | | } |
| | | String strning = builder.toString(); |
| | | return strning.toUpperCase(); |
| | | |
| | | data = builder.toString().toUpperCase(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | } |