JAva android(ios)汎用aes暗号解読
詳細
暗号化方式:1.テキストAESを先に暗号化する2.Base 64に戻って符号化する
復号方式:1.データをBase 64復号する2.AES復号を行う
android独自Base 64暗号解読
http://happyqing.iteye.com/blog/2287679
参照先:
.NET/android/java/iOS AES汎用暗号解読http://www.cnblogs.com/jys509/p/4768120.html
暗号化方式:1.テキストAESを先に暗号化する2.Base 64に戻って符号化する
復号方式:1.データをBase 64復号する2.AES復号を行う
package com.urthinker.jxsh.util;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* AES , AES , Base64 ;
* @author happyqing
* @since 2016.3.30
*/
public class AESOperator {
/*
* Key 26 AES-128-CBC ,key 16 。
*/
private String sKey = "0123456789abcdef";//key,
private String ivParameter = "1020304050607080";// ,
private static AESOperator instance = null;
private AESOperator() {
}
public static AESOperator getInstance() {
if (instance == null)
instance = new AESOperator();
return instance;
}
//
public String encrypt(String sSrc) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] raw = sKey.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());// CBC , iv,
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
return new BASE64Encoder().encode(encrypted);// BASE64 。
}
//
public String decrypt(String sSrc) throws Exception {
try {
byte[] raw = sKey.getBytes("ASCII");
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);// base64
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original, "utf-8");
return originalString;
} catch (Exception ex) {
return null;
}
}
public static void main(String[] args) throws Exception {
//
//String cSrc = "[{\"request_no\":\"1001\",\"service_code\":\"FS0001\",\"contract_id\":\"100002\",\"order_id\":\"0\",\"phone_id\":\"13913996922\",\"plat_offer_id\":\"100094\",\"channel_id\":\"1\",\"activity_id\":\"100045\"}]";
String cSrc = "15811111111";
AESOperator.getInstance();
//
long lStart = System.currentTimeMillis();
String enString = AESOperator.getInstance().encrypt(cSrc);
System.out.println(" :" + enString);
long lUseTime = System.currentTimeMillis() - lStart;
System.out.println(" :" + lUseTime + " ");
//
lStart = System.currentTimeMillis();
String DeString = AESOperator.getInstance().decrypt(enString);
System.out.println(" :" + DeString);
lUseTime = System.currentTimeMillis() - lStart;
System.out.println(" :" + lUseTime + " ");
}
}
android独自Base 64暗号解読
http://happyqing.iteye.com/blog/2287679
参照先:
.NET/android/java/iOS AES汎用暗号解読http://www.cnblogs.com/jys509/p/4768120.html