看板 AndroidDev 關於我們 聯絡資訊
各位高手好 小弟最近在做APP API接口要載入key java範例是這樣的 public static String Signature(String xData, String AppKey) throws java.security.SignatureException { try { final Base64.Encoder encoder = Base64.getEncoder(); // get an hmac_sha1 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(AppKey.getBytes("UTF-8"),"HmacSHA1"); // get an hmac_sha1 Mac instance and initialize with the signing key Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); // compute the hmac on input data bytes byte[] rawHmac = mac.doFinal(xData.getBytes("UTF-8")); String result = encoder.encodeToString(rawHmac); return result; } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : "+ e.getMessage()); } } 放到Android Studio上 1.一直抓不到Encoder這個method 是不是import 要改抓JAVA 的包才行 或者在Android上不是這樣寫的 小弟也看了Base64的方法有encode沒有encoder 2. throws java.security.SignatureException 這是JAVA的寫法 在Android上是不是直接刪掉 Android好像不用throws這種方法 -- 大熱透威力彩兌獎 https://play.google.com/store/apps/details?id=sodf.s125aaqwe&hl=zh-TW -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.137.206.29 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1512366449.A.EDB.html ※ 編輯: jerryxin (220.137.206.29), 12/04/2017 13:48:42
ssccg: android在API26才有java8的class(java.util.Base64) 12/04 15:29
ssccg: 要用android.util.Base64 12/04 15:29
ssccg: 怎麼用看javadoc不就很清楚了... 12/04 15:30
ssccg: Android沒有不用throw,exception處理都是一樣的 12/04 15:30