呼叫方法:// 演算法名
public static final string key_name = "aes";
// 加解密演算法/模式/填充方式
// ecb模式只用金鑰即可對資料進行加密解密,cbc模式需要新增乙個iv
public static final string cipher_algorithm = "aes/cbc/pkcs7padding";
/*** @param encrypted 目標密文
* @param session_key 會話id
* @param iv 加密演算法的初始向量
*/public static string wxdecrypt(string encrypted, string session_key, string iv) catch (exception e)
return json;
}/**
* 初始化金鑰
*/public static void init() throws exception
/*** 生成iv
*/public static algorithmparameters generateiv(byte iv) throws exception
/*** 生成解密
*/public static byte decrypt(byte encrypteddata, byte keybytes, algorithmparameters iv)
throws exception
/*** @param encrypteddata
* @param sessionkey
* @param iv
* @return
*/public static string getuserinfo(string encrypteddata, string sessionkey, string iv)
// 初始化
security.addprovider(new bouncycastleprovider());
cipher cipher = cipher.getinstance("aes/cbc/pkcs7padding", "bc");
secretkeyspec spec = new secretkeyspec(keybyte, "aes");
algorithmparameters parameters = algorithmparameters
.getinstance("aes");
parameters.init(new ivparameterspec(ivbyte));
cipher.init(cipher.decrypt_mode, spec, parameters);// 初始化
byte resultbyte = cipher.dofinal(databyte);
if (null != resultbyte && resultbyte.length > 0)
} catch (nosuchalgorithmexception e) catch (nosuchpaddingexception e) catch (invalidparameterspecexception e) catch (illegalblocksizeexception e) catch (badpaddingexception e) catch (unsupportedencodingexception e) catch (invalidkeyexception e) catch (invalidalgorithmparameterexception e) catch (nosuchproviderexception e)
return result;
}
兩個輸出結果是一樣的,兩種方法實現解密!string encrypteddata = "";
string iv = "";
string session_key = "";
string json = miniaesutil.getuserinfo(encrypteddata, session_key, iv);
string wxdecrypt = miniaesutil.wxdecrypt(encrypteddata, session_key, iv);
system.out.println(json);
system.out.println(wxdecrypt);
(微信小程式)一 初識微信小程式
需要看的 先是檔案目錄 一 pages 他存放於多個頁面 如 index log頁面。可以把他裡面的每個資料夾看成乙個整體。這個整體存放著 html css 和 資料 1 index資料夾 存放的index頁面的目錄。2 index.js 他可以處理得到 ajax 或自定義定義的資料。把得到的值封裝...
微信小程式
2.單獨設定某一頁面下的頂部欄的背景顏色,在其對應的.json檔案下修改即可 3.this.setdata 注意 onload函式下面執行的是非同步操作,非同步操作裡面this.data.直接賦值,是無效的,必須使用this.setdata this.setdata msg he llo wor l...
微信小程式
你好!這是你第一次使用markdown編輯器所展示的歡迎頁。如果你想學習如何使用markdown編輯器,可以仔細閱讀這篇文章,了解一下markdown的基本語法知識。全新的介面設計,將會帶來全新的寫作體驗 在創作中心設定你喜愛的 高亮樣式,markdown將 片顯示選擇的高亮樣式進行展示 全新的ka...