| | |
| | | package com.lcjian.library.util.security; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.InvalidKeyException; |
| | | import java.security.Key; |
| | | import java.security.NoSuchAlgorithmException; |
| | |
| | | try { |
| | | Cipher enCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");// 得到加密对象Cipher |
| | | enCipher.init(Cipher.ENCRYPT_MODE, key, iv);// 设置工作模式为加密模式,给出密钥和向量 |
| | | byte[] pasByte = enCipher.doFinal(data.getBytes("utf-8")); |
| | | byte[] pasByte = enCipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); |
| | | result = Base64.encodeToString(pasByte, Base64.DEFAULT); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | deCipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); |
| | | deCipher.init(Cipher.DECRYPT_MODE, key, iv); |
| | | byte[] pasByte = deCipher.doFinal(Base64.decode(data, Base64.DEFAULT)); |
| | | result = new String(pasByte, "UTF-8"); |
| | | result = new String(pasByte, StandardCharsets.UTF_8); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |