How to generate a signature correctly?

I generate this, but the server responds that the signature is not correct.

String toHash = URLEncoder.encode("POST&https://" + url + "&oauth_callback=oob&oauth_consumer_key=" + key + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + timeStamp + "&oauth_nonce=" + timeStamp); String hash = computeHmac(toHash, secret); 

...

 public String computeHmac(String baseString, String key) { Mac mac = Mac.getInstance("HmacSHA1"); SecretKeySpec secret = new SecretKeySpec(key.getBytes(), mac.getAlgorithm()); mac.init(secret); byte[] digest = mac.doFinal(baseString.getBytes()); return new String(Base64.encodeBase64(digest)); } 
  • What is this service? Twitter? - Lucky_spirit
  • not. general case of a service built on OAuth. - Vladyslav Matviienko

0