Package tigase.form
Class SignatureCalculator
- java.lang.Object
-
- tigase.form.SignatureCalculator
-
public class SignatureCalculator extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringSUPPORTED_TYPE
-
Constructor Summary
Constructors Constructor Description SignatureCalculator()SignatureCalculator(String oauthConsumerKey, String oauthConsumerSecret)SignatureCalculator(String oauthToken, String oauthTokenSecret, String oauthConsumerKey, String oauthConsumerSecret)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEmptyFields(Form form)StringcalculateSignature(JID to, Form form)Calculate signature of given form.protected static Stringescape(String s)StringgetOauthConsumerKey()StringgetOauthConsumerSecret()StringgetOauthToken()StringgetOauthTokenSecret()protected byte[]h(byte[] data)protected static byte[]hmac(SecretKey key, byte[] data)booleanisMethodSupported(String fOauthSignatureMethod)protected SecretKeykey(byte[] key)protected StringrandomString()voidsetOauthConsumerKey(String oauthConsumerKey)voidsetOauthConsumerSecret(String oauthConsumerSecret)voidsetOauthToken(String oauthToken)voidsetOauthTokenSecret(String oauthTokenSecret)voidsign(JID to, String nonce, long timestamp, Form form)Sign given Form.voidsign(JID to, Form form)Sign given form with current time.
-
-
-
Field Detail
-
SUPPORTED_TYPE
public static final String SUPPORTED_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
hmac
protected static byte[] hmac(SecretKey key, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException
-
addEmptyFields
public void addEmptyFields(Form form)
-
calculateSignature
public String calculateSignature(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
Calculate signature of given form. Form will not be changed.- Parameters:
to- the full destination address, including resource, if any.form- form to sign.- Returns:
- Signature of form.
- Throws:
InvalidKeyExceptionNoSuchAlgorithmException
-
getOauthConsumerKey
public String getOauthConsumerKey()
- Returns:
- the oauthConsumerKey
-
setOauthConsumerKey
public void setOauthConsumerKey(String oauthConsumerKey)
- Parameters:
oauthConsumerKey- the oauthConsumerKey to set
-
getOauthConsumerSecret
public String getOauthConsumerSecret()
- Returns:
- the oauthConsumerSecret
-
setOauthConsumerSecret
public void setOauthConsumerSecret(String oauthConsumerSecret)
- Parameters:
oauthConsumerSecret- the oauthConsumerSecret to set
-
getOauthToken
public String getOauthToken()
- Returns:
- the oauthToken
-
setOauthToken
public void setOauthToken(String oauthToken)
- Parameters:
oauthToken- the oauthToken to set
-
getOauthTokenSecret
public String getOauthTokenSecret()
- Returns:
- the oauthTokenSecret
-
setOauthTokenSecret
public void setOauthTokenSecret(String oauthTokenSecret)
- Parameters:
oauthTokenSecret- the oauthTokenSecret to set
-
isMethodSupported
public boolean isMethodSupported(String fOauthSignatureMethod)
-
sign
public void sign(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
Sign given form with current time. Signature will be added to form.- Parameters:
to- the full destination address, including resource, if any.form- form to sign.- Throws:
InvalidKeyExceptionNoSuchAlgorithmException
-
sign
public void sign(JID to, String nonce, long timestamp, Form form) throws InvalidKeyException, NoSuchAlgorithmException
Sign given Form. Signature will be added to form.- Parameters:
to- the full destination address, including resource, if any.nonce- A nonce value that the client has to set. Can be a random alphanumerical string.timestamp- Number of seconds since 1st of January 1970, 00:00:00 GMT. The client has to set this at the time of signature.form- form to sign.- Throws:
InvalidKeyExceptionNoSuchAlgorithmException
-
h
protected byte[] h(byte[] data) throws NoSuchAlgorithmException- Throws:
NoSuchAlgorithmException
-
key
protected SecretKey key(byte[] key)
-
randomString
protected String randomString()
-
-