OAuth1aParameters { String calculateSignature(String signatureBase) { try { final String key = getSigningKey(); final byte[] signatureBaseBytes = signatureBase.getBytes(UrlUtils.UTF8); final byte[] keyBytes = key.getBytes(UrlUtils.UTF8); final SecretKey secretKey = new SecretKeySpec(keyBytes, "HmacSHA1"); final Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); final byte[] signatureBytes = mac.doFinal(signatureBaseBytes); return ByteString.of(signatureBytes, 0, signatureBytes.length).base64(); } catch (InvalidKeyException e) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to calculate signature", e); return ""; } catch (NoSuchAlgorithmException e) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to calculate signature", e); return ""; } catch (UnsupportedEncodingException e) { Twitter.getLogger().e(TwitterCore.TAG, "Failed to calculate signature", e); return ""; } } OAuth1aParameters(TwitterAuthConfig authConfig, TwitterAuthToken authToken,
            String callback, String method, String url, Map<String, String> postParams); String getAuthorizationHeader();  }
@Test public void testCalculateSignature() { for (TestParameters testParameters : TEST_PARAMETERS) { final OAuth1aParameters oAuth1aParameters = toOAuth1aParameters(testParameters); final String signature = oAuth1aParameters.calculateSignature(testParameters.expectedSignatureBase); assertEquals(testParameters.expectedSignature, signature); } }