tigase.form

## Class SignatureCalculator

- java.lang.Object
- - tigase.form.SignatureCalculator

-     public class SignatureCalculator
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SUPPORTED_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and 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 and Description
    --- | ---
    `void` | `addEmptyFields(Form form)`
    `String` | `calculateSignature(JID to, Form form)` Calculate signature of given form.
    `protected static String` | `escape(String s)`
    `String` | `getOauthConsumerKey()`
    `String` | `getOauthConsumerSecret()`
    `String` | `getOauthToken()`
    `String` | `getOauthTokenSecret()`
    `protected byte[]` | `h(byte[] data)`
    `protected static byte[]` | `hmac(SecretKey key, byte[] data)`
    `boolean` | `isMethodSupported(String fOauthSignatureMethod)`
    `protected SecretKey` | `key(byte[] key)`
    `protected String` | `randomString()`
    `void` | `setOauthConsumerKey(String oauthConsumerKey)`
    `void` | `setOauthConsumerSecret(String oauthConsumerSecret)`
    `void` | `setOauthToken(String oauthToken)`
    `void` | `setOauthTokenSecret(String oauthTokenSecret)`
    `void` | `sign(JID to, Form form)` Sign given form with current time.
    `void` | `sign(JID to, String nonce, long timestamp, Form form)` Sign given Form.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SUPPORTED_TYPE

          public static final String SUPPORTED_TYPE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SignatureCalculator

          public SignatureCalculator()

    - #### SignatureCalculator

          public SignatureCalculator(String oauthConsumerKey,
                                     String oauthConsumerSecret)

    - #### SignatureCalculator

          public SignatureCalculator(String oauthToken,
                                     String oauthTokenSecret,
                                     String oauthConsumerKey,
                                     String oauthConsumerSecret)

  - ### Method Detail

    - #### escape

          protected static String escape(String s)

    - #### hmac

          protected static byte[] hmac(SecretKey key,
                                       byte[] data)
                                throws NoSuchAlgorithmException,
                                       InvalidKeyException

      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:
        `InvalidKeyException`
        `NoSuchAlgorithmException`

    - #### getOauthConsumerKey

          public String getOauthConsumerKey()

      Returns:
        the oauthConsumerKey

    - #### getOauthConsumerSecret

          public String getOauthConsumerSecret()

      Returns:
        the oauthConsumerSecret

    - #### getOauthToken

          public String getOauthToken()

      Returns:
        the oauthToken

    - #### getOauthTokenSecret

          public String getOauthTokenSecret()

      Returns:
        the oauthTokenSecret

    - #### h

          protected byte[] h(byte[] data)
                      throws NoSuchAlgorithmException

      Throws:
        `NoSuchAlgorithmException`

    - #### isMethodSupported

          public boolean isMethodSupported(String fOauthSignatureMethod)

    - #### key

          protected SecretKey key(byte[] key)

    - #### randomString

          protected String randomString()

    - #### setOauthConsumerKey

          public void setOauthConsumerKey(String oauthConsumerKey)

      Parameters:
        `oauthConsumerKey` - the oauthConsumerKey to set

    - #### setOauthConsumerSecret

          public void setOauthConsumerSecret(String oauthConsumerSecret)

      Parameters:
        `oauthConsumerSecret` - the oauthConsumerSecret to set

    - #### setOauthToken

          public void setOauthToken(String oauthToken)

      Parameters:
        `oauthToken` - the oauthToken to set

    - #### setOauthTokenSecret

          public void setOauthTokenSecret(String oauthTokenSecret)

      Parameters:
        `oauthTokenSecret` - the oauthTokenSecret to set

    - #### 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:
        `InvalidKeyException`
        `NoSuchAlgorithmException`

    - #### 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:
        `InvalidKeyException`
        `NoSuchAlgorithmException`

Copyright © 2017 "Tigase, Inc.". All rights reserved.