Implementing RSA-SHA1 signature algorithm in Java (creating a private key for use with OAuth RSA-SHA

Posted by The Elite Gentleman on Stack Overflow See other posts from Stack Overflow or by The Elite Gentleman
Published on 2010-03-30T12:26:24Z Indexed on 2010/03/30 13:13 UTC
Read the original article Hit count: 582

Filed under:
|
|

Hi everyone,

As you know, OAuth can support RSA-SHA1 Signature. I have an OAuthSignature interface that has the following method

public String sign(String data, String consumerSecret, String tokenSecret) throws GeneralSecurityException;

I successfully implemented and tested HMAC-SHA1 Signature (which OAuth Supports) as well as the PLAINTEXT "signature".

I have searched google and I have to create a private key if I need to use SHA1withRSA signature: Sample code:

  /**
   * Signs the data with the given key and the provided algorithm.
   */
  private static byte[] sign(PrivateKey key,
                             String data)
      throws GeneralSecurityException {

    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(key);
    signature.update(data.getBytes());
    return signature.sign();
  }

Now, How can I take the OAuth key (which is key = consumerSecret&tokenSecret) and create a PrivateKey to use with SHA1withRSA signature?

Thanks

© Stack Overflow or respective owner

Related posts about digital-signature

Related posts about java