为 Twitter OAuth 生成哈希
Generate Hash for Twitter OAuth
我正在尝试按照 Twitter 开发者页面中的说明生成哈希:https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature.html
signatureBaseString = "POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521";
signingKey = "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE";
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(new SecretKeySpec(Base64.decodeBase64(signingKey), "HmacSHA1"));
String sig = new String(Base64.encodeBase64(mac.doFinal(signatureBaseString.getBytes())));
return URLEncoder.encode(sig, "UTF-8");
但是我的签名与 Twitter 页面上的不同。有什么想法吗?
签名密钥未以 base 64 编码,因此您不能对其进行 base 64 解码。
我正在尝试按照 Twitter 开发者页面中的说明生成哈希:https://developer.twitter.com/en/docs/basics/authentication/guides/creating-a-signature.html
signatureBaseString = "POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521";
signingKey = "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE";
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(new SecretKeySpec(Base64.decodeBase64(signingKey), "HmacSHA1"));
String sig = new String(Base64.encodeBase64(mac.doFinal(signatureBaseString.getBytes())));
return URLEncoder.encode(sig, "UTF-8");
但是我的签名与 Twitter 页面上的不同。有什么想法吗?
签名密钥未以 base 64 编码,因此您不能对其进行 base 64 解码。