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