| | |
| | | package com.lcjian.library.util.security; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.InvalidKeyException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.SecureRandom; |
| | |
| | | byte[] enCodeFormat = secretKey.getEncoded(); |
| | | SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); |
| | | Cipher cipher = Cipher.getInstance("AES");// 创建密码器 |
| | | byte[] byteContent = content.getBytes("utf-8"); |
| | | byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); |
| | | cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化 |
| | | byte[] result = cipher.doFinal(byteContent); |
| | | return result; // 加密 |
| | |
| | | } catch (NoSuchPaddingException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvalidKeyException e) { |
| | | e.printStackTrace(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } catch (IllegalBlockSizeException e) { |
| | | e.printStackTrace(); |