网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

Java實現小程序用戶信息解密

發(fā)布時間:2018-02-10 12:05 所屬欄目:小程序開發(fā)教程

Node,php,Phthon,C++地址:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=1415
以及C#的代碼:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=1398
ruby:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=1541
go:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=539
 
加上這個,已經比較齊全了,值得參考,另外大家可以搜索一下“登錄”這個關鍵詞,查看一些文章關于登錄的,用于輔助;
關鍵代碼:

public String decrypt(String encryptedData, String sessionKey, String iv, String encodingFormat) throws Exception {

   try {

      Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");

      BASE64Decoder base64Decoder = new BASE64Decoder();

      byte[] _encryptedData = base64Decoder.decodeBuffer(encryptedData);

      byte[] _sessionKey = base64Decoder.decodeBuffer(sessionKey);

      byte[] _iv = base64Decoder.decodeBuffer(iv);

      SecretKeySpec secretKeySpec = new SecretKeySpec(_sessionKey, "AES");

      IvParameterSpec ivParameterSpec = new IvParameterSpec(_iv);

      cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);

      byte[] original = cipher.doFinal(_encryptedData);

      byte[] bytes = WxPKCS7Encoder.decode(original);

      String originalString = new String(bytes, encodingFormat);      return originalString;

   } catch (Exception ex) {

      return null;

   }

}

依賴類 WxPKCS7Encoder.javaclass WxPKCS7Encoder {

   static Charset CHARSET = Charset.forName("utf-8");

   static int BLOCK_SIZE = 32;



   /**

    * 獲得對明文進行補位填充的字節(jié).

    * 

    * @param count 需要進行填充補位操作的明文字節(jié)個數

    * @return 補齊用的字節(jié)數組

    */

   static byte[] encode(int count) {

      // 計算需要填充的位數

      int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);

      if (amountToPad == 0) {

         amountToPad = BLOCK_SIZE;

      }

      // 獲得補位所用的字符

      char padChr = chr(amountToPad);

      String tmp = new String();

      for (int index = 0; index < amountToPad; index++) {

         tmp += padChr;

      }

      return tmp.getBytes(CHARSET);

   }



   /**

    * 刪除解密后明文的補位字符

    * 

    * @param decrypted 解密后的明文

    * @return 刪除補位字符后的明文

    */

   static byte[] decode(byte[] decrypted) {

      int pad = (int) decrypted[decrypted.length - 1];

      if (pad < 1 || pad > 32) {

         pad = 0;

      }

      return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);

   }



   /**

    * 將數字轉化成ASCII碼對應的字符,用于對明文進行補碼

    * 

    * @param a 需要轉化的數字

    * @return 轉化得到的字符

    */

   static char chr(int a) {

      byte target = (byte) (a & 0xFF);

      return (char) target;

   }



}


jdk版本1.8


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/21977.html 復制鏈接 如需定制請聯系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×