· 9 years ago · Jan 24, 2017, 12:56 PM
1public static String encrypt(String plainText){
2 String encryptedText="";
3 try {
4 SecretKey secretKey = getKey();
5 byte[] plainTextByte = plainText.getBytes();
6 Cipher cipher = Cipher.getInstance("AES");
7 cipher.init(Cipher.ENCRYPT_MODE, secretKey);
8 byte[] encryptedByte = cipher.doFinal(plainTextByte);
9
10}
11 return plainText;
12}
13
14private static SecretKey getKey() throws NoSuchAlgorithmException {
15 MessageDigest md = MessageDigest.getInstance("SHA-256");
16 md.update("VMEz(JHhbt^J7T34GB/PZ}QUU7v^d-/".getBytes());
17 byte[] encryptionKey = md.digest();
18 SecretKey secretKey = new SecretKeySpec(encryptionKey, "AES");
19 return secretKey;
20}