Java使用HMAC-SHA1算法

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

String secret = mConsumerSecret + "&" + mOauthToken;

SecretKey secretKey = new SecretKeySpec(secret.getBytes("US-ASCII"), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKey);

byte[] text = builder.toString().getBytes("US-ASCII");
byte[] finalText = mac.doFinal(text);
String base64Text = Base64.encodeToString(finalText, Base64.DEFAULT);
return encode(base64Text.trim());