### Question:
OAuthUtil { static String createSignature(String signatureBaseString, String signingKey) { try { SecretKey key = new SecretKeySpec(signingKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(key); byte[] hmacBytes = mac.doFinal(signatureBaseString.getBytes()); return new String(Base64.encodeBase64(hmacBytes)); } catch (InvalidKeyException e) { throw new IllegalStateException("InvalidKeyException when creating OAuth signature: " + e.getMessage(), e); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "NoSuchAlgorithmException when creating OAuth signature: " + e.getMessage(), e); } catch (IllegalStateException e) { throw new IllegalStateException("IllegalStateException when creating OAuth signature: " + e.getMessage(), e); } } OAuthUtil(OAuthParams params); HttpRequest2 createSignedRequest(HttpRequest2 httpRequest); String createAuthorization(HttpMethod method, String url, List<? extends Entry<String, String>> params); static final String AUTHORIZATION_HEADER_KEY; }### Answer:
@Test public void testCreateSignature() { String signatureBaseString = OAuthUtil.createSignatureBaseString(HTTP_METHOD, BASE_URL, PARAMS); String signingKey = OAuthUtil.createSigningKey(CONSUMER_SECRET, TOKEN_SECRET); String signature = OAuthUtil.createSignature(signatureBaseString, signingKey); assertEquals("tnnArxj06cWHq44gCs1OSKk/jLY=", signature); }