I would consider using a library that already does this for you. There are
three things that MAY cause you problems.

1) What is the value of the key that you are passing in? The key to sign
should be oauthParamEncode(consumerSecret) + "&" +
oauthParamEncode(tokenSecret). I define oauthParamEncode as per the
specification [1]. Note if the tokenSecret is null it should be empty
String.

2) The signature you compare to the OAuth Playground should also have
oauthParamEncode done on it.

3) Depending on your default encoding you may have issues as well. May be
good to pass in "UTF-8" into the getBytes.

[1] http://oauth.net/core/1.0a#encoding_parameters

On Thu, Oct 15, 2009 at 12:45 AM, Partha <[email protected]>wrote:

>
> I am using the following code to sign the base string. Is this
> correct?
>
> My problem is, I generate the base string using OAuth playground and
> when I create the signature it does not match with the one generated
> in the playground and my subsequent request fails with HTTP error code
> 400
>
> What is wrong in this?
>
>
> public final class Encoder {
>
>    private static final String SIGNING_ALGORITHM = "HmacSHA1";
>
>    private Encoder() {
>        // nothing to do.
>    }
>
>    public static String sign(final String source, final String key) {
>        if (key == null) {
>            throw new IllegalArgumentException("key cannot be null");
>        }
>        Mac mac = null;
>        try {
>            mac = Mac.getInstance(SIGNING_ALGORITHM);
>            mac.init(new SecretKeySpec(key.getBytes(),
> SIGNING_ALGORITHM));
>        } catch (Exception e) {
>            throw new RuntimeException(e);
>        }
>        final byte[] result = mac.doFinal(source.getBytes());
>        final String signature = new String(Base64.encodeBase64
> (result));
>        return signature;
>    }
> }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OAuth" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to