叶测试 - 安卓
type: channel
link: https://r1989.com/tag/%E5%AE%89%E5%8D%93/
items: 安卓端JAVA AES加密对应处理类

安卓端JAVA AES加密对应处理类
type: item
date: 2017-10-30T08:00:00+00:00
description: // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.wiggins.teaching.utils; import android.util.Base64; import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class AESHelper { private static final String CipherMode = "AES/ECB/PKCS5Padding"; private static final String password = "Coding@xxx.China"; public AESHelper() { } private static SecretKeySpec createKey(String password) { byte[] data = null; if(password == null) { password = ""; } StringBuffer sb = new StringBuffer(16); sb.append(password); while(sb.length() < 16) { sb.append("0"); } if(sb.length() > 16) { sb.setLength(16); } try { data = sb.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException var4) { var4.printStackTrace(); } return new SecretKeySpec(data, "AES"); } public static byte[] encrypt(byte[] content, String password) { try { SecretKeySpec e = createKey(password); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(1, e); byte[] result = cipher.doFinal(content); return result; } catch (Exception var5) { var5.printStackTrace(); return null; } } public static String encrypt(String content, String password) { byte[] data = null; try { data = content.getBytes("UTF-8"); } catch (Exception var4) { var4.printStackTrace(); } data = encrypt(data, password); String result = Base64.encodeToString(data, 2); return result; } public static String encrypt(String content) { byte[] data = null; try { data = content.getBytes("UTF-8"); } catch (Exception var3) { var3.printStackTrace(); } data = encrypt(data, "sgg45747ss223455"); String result = Base64.encodeToString(data, 2); return result; } public static byte[] decrypt(byte[] content, String password) { try { SecretKeySpec e = createKey(password); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(2, e); byte[] result = cipher.doFinal(content); return result; } catch (Exception var5)…