thanks. i changed that MessageDigest md =
MessageDigest.getInstance("SHA-1"). it's working now.On Thu, Dec 11, 2014 at 9:25 PM, Vanjikumaran Sivajothy <[email protected]> wrote: > On you code it seem you are using the MD5 to hash. However expected > hashing mechanism is SH-1 according to doc. > > Hence, please try with MessageDigest md = > MessageDigest.getInstance("SHA-1"); > > MessageDigest md = MessageDigest.getInstance("MD5"); > On Thu, Dec 11, 2014 at 9:21 PM, Vanii Thiyagarajah <[email protected]> > wrote: > >> I am implementing the slideshare Connector using slideshare API. >> >> I have to set this to the SHA1 hash of the concatenation of the shared >> secret and the timestamp (ts). i.e. SHA1 (sharedsecret + timestamp). >> >> >> package org.wso2.carbon.connector; >> >> import java.math.BigInteger; >> import java.security.MessageDigest; >> import java.util.*; >> import org.apache.synapse.MessageContext; >> import java.io.UnsupportedEncodingException; >> import java.security.InvalidKeyException; >> import java.security.NoSuchAlgorithmException; >> >> import org.apache.synapse.SynapseException; >> import org.apache.synapse.mediators.AbstractMediator; >> >> /** >> * Created by vanii on 12/9/14. >> */ >> public class Encoder extends AbstractMediator { >> >> public static final String sha1Key = "uri.var.sha1Key"; >> >> public void generateHash(MessageContext msgctx) throws >> UnsupportedEncodingException,NoSuchAlgorithmException, InvalidKeyException { >> StringBuilder baseString = new StringBuilder(); >> * MessageDigest md = MessageDigest.getInstance("MD5");* >> >> >> String timeStamp=String.valueOf(System.currentTimeMillis() / >> 1000); >> msgctx.setProperty("uri.var.ts",timeStamp); >> >> >> String input = msgctx.getProperty("uri.var.sha1Key").toString() + >> timeStamp; >> md.update(input.getBytes()); >> >> String hash = String.format("%032x", new BigInteger(1, >> md.digest())); >> msgctx.setProperty("uri.var.hash",hash); >> } >> >> public boolean mediate(MessageContext msgctx) { >> try { >> generateHash(msgctx); >> } catch (Exception e) { >> throw new SynapseException(e); >> } >> return true; >> } >> } >> >> >> >> I am getting but the response says hashing is not correct. >> >> >> [1] >> [2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> GET >> https://www.slideshare.net/api/2/get_slideshow?api_key=4yCEGJou&ts=1418309760&hash=901c42f4bb22ee6617f2c82c81547bd3ad9b5b95&slideshow_id=124324&slideshow_url=http://www.slideshare.net/cocog520/-124324 >> HTTP/1.1 >> [2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> >> Accept-Language: en-US,en;q=0.8 >> [2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> Cookie: >> SERVERID=r87|VImwL|VImwJ >> [2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> >> Accept-Encoding: gzip,deflate >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Origin: >> chrome-extension:// >> hgmloofddffdnphfgcellkdfbfbjeloo >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> >> Content-Type: application/json >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Accept: */* >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Host: >> www.slideshare.net:80 >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Connection: >> Keep-Alive >> [2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> User-Agent: >> Synapse-PT-HttpComponents-NIO >> [2014-12-11 20:26:01,654] DEBUG - wire << "GET >> https://www.slideshare.net/api/2/get_slideshow?api_key=4yCEGJou&ts=1418309760&hash=901c42f4bb22ee6617f2c82c81547bd3ad9b5b95&slideshow_id=124324&slideshow_url=http://www.slideshare.net/cocog520/-124324 >> HTTP/1.1[\r][\n]" >> [2014-12-11 20:26:01,654] DEBUG - wire << "Accept-Language: >> en-US,en;q=0.8[\r][\n]" >> [2014-12-11 20:26:01,654] DEBUG - wire << "Cookie: >> SERVERID=r87|VImwL|VImwJ[\r][\n]" >> [2014-12-11 20:26:01,654] DEBUG - wire << "Accept-Encoding: >> gzip,deflate[\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "Origin: >> chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo[\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "Content-Type: >> application/json[\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "Accept: */*[\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "Host: www.slideshare.net:80 >> [\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "Connection: Keep-Alive[\r][\n]" >> [2014-12-11 20:26:01,655] DEBUG - wire << "User-Agent: >> Synapse-PT-HttpComponents-NIO[\r][\n]" >> >> >> i am getting the error response in Rest Client >> >> <?xml version="1.0" encoding="UTF-8" ?> >> <SlideShareServiceError> >> <Message ID="1"> >> Failed API validation >> </Message> >> </SlideShareServiceError> >> >> > > > -- > Sivajothy Vanjikumaran > *Senior Software Engineer* > *Integration Technologies Team* > *WSO2 Inc. http://wso2.com <http://wso2.com/>* > *Mobile:(+94)777219209* > [image: Facebook] <https://www.facebook.com/vanjikumaran> [image: Twitter] > <https://twitter.com/vanjikumaran> [image: LinkedIn] > <http://www.linkedin.com/pub/vanjikumaran-sivajothy/25/b31/293> [image: > Blogger] <http://vanjikumaran.blogspot.com/> [image: SlideShare] > <http://www.slideshare.net/vanjikumaran> > > This communication may contain privileged or other > confidential information and is intended exclusively for the addressee/s. > If you are not the intended recipient/s, or believe that you may > have received this communication in error, please reply to the > sender indicating that fact and delete the copy you received and in > addition, you should not print, copy, re-transmit, disseminate, or > otherwise use the information contained in this communication. > Internet communications cannot be guaranteed to be timely, secure, error > or virus-free. The sender does not accept liability for any errors > or omissions >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
