package com.ads.web.app.network;
import android.util.Base64;
import java.security.MessageDigest;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AESCrypt {
public static final String SEED_16_CHARACTER = "DaCheAPPAesKey";
private final Cipher cipher;
private static AESCrypt instance;
private final SecretKeySpec key;
private AlgorithmParameterSpec spec;
static {
}
public AESCrypt() throws Exception {
super();
MessageDigest v0 = MessageDigest.getInstance("SHA-256");
v0.update("DaCheAPPAesKey".getBytes("UTF-8"));
byte[] v1 = new byte[32];
System.arraycopy(v0.digest(), 0, v1, 0, v1.length);
this.cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
this.key = new SecretKeySpec(v1, "AES");
this.spec = this.getIV();
}
public String decrypt(String arg5) throws Exception {
this.cipher.init(2, this.key, this.spec);
return new String(this.cipher.doFinal(Base64.decode(arg5, 0)), "UTF-8");
}
public String encrypt(String arg5) throws Exception {
this.cipher.init(1, this.key, this.spec);
return new String(Base64.encode(this.cipher.doFinal(arg5.getBytes("UTF-8")), 0), "UTF-8");
}
public AlgorithmParameterSpec getIV() {
return new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
}
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
public static AESCrypt getInstance() {
try {
if(AESCrypt.instance == null) {
AESCrypt.instance = new AESCrypt();
}
return AESCrypt.instance;
}
catch(Exception ) {
return null;
}
}
}
真么让iv输出出来呀
AESCrypt aes = new AESCrypt();
String str= aes.decrypt(参数);