1 private static String generateSignature(String baseString, 2 String consumerKeySecret, String tokenSecret) { 3 4 byte[] byteHMAC = null; 5 try { 6 Mac mac = Mac.getInstance("HmacSHA1"); 7 SecretKeySpec spec; 8 String oauthSignature = encode(consumerKeySecret) + "&" 9 + ((tokenSecret != null) ? encode(tokenSecret) : ""); 10 spec = new SecretKeySpec(oauthSignature.getBytes(), "HmacSHA1"); 11 mac.init(spec); 12 byteHMAC = mac.doFinal(baseString.getBytes()); 13 } catch (InvalidKeyException e) { 14 e.printStackTrace(); 15 } catch (NoSuchAlgorithmException ignore) { 16 // should never happen 17 } 18 return new BASE64Encoder().encode(byteHMAC); 19 }
Android学习笔记——OAuth完全手册_国内篇 (3)
内容版权声明:除非注明,否则皆为本站原创文章。