Example usage for org.springframework.security.oauth.common.signature HMAC_SHA1SignatureMethod sign

List of usage examples for org.springframework.security.oauth.common.signature HMAC_SHA1SignatureMethod sign

Introduction

In this page you can find the example usage for org.springframework.security.oauth.common.signature HMAC_SHA1SignatureMethod sign.

Prototype

public String sign(String signatureBaseString) 

Source Link

Document

Sign the signature base string.

Usage

From source file:net.oauth.signature.GoogleCodeCompatibilityTests.java

/**
 * tests compatibilty with the google code HMAC_SHA1 signature.
 *///w ww.  j  a  v  a 2 s .c  o m
@Test
public void testHMAC_SHA1_1() throws Exception {
    HMAC_SHA1 theirMethod = new HMAC_SHA1();
    String baseString = "GET&http%3A%2F%2Flocalhost%3A8080%2Fgrailscrowd%2Foauth%2Frequest_token&oauth_consumer_key%3Dtonrconsumerkey%26oauth_nonce%3D1227967049787975000%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1227967049%26oauth_version%3D1.0";
    theirMethod.setConsumerSecret("xxxxxx");
    theirMethod.setTokenSecret("");
    SecretKeySpec spec = new SecretKeySpec("xxxxxx&".getBytes("UTF-8"), HMAC_SHA1SignatureMethod.MAC_NAME);
    HMAC_SHA1SignatureMethod ourMethod = new HMAC_SHA1SignatureMethod(spec);
    String theirSignature = theirMethod.getSignature(baseString);
    String ourSignature = ourMethod.sign(baseString);
    assertEquals(theirSignature, ourSignature);
}