Package tigase.form

## Class SignatureCalculator

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

-     public class SignatureCalculator
      extends java.lang.Object

- - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SignatureCalculator()` |
    `SignatureCalculator​(java.lang.String oauthConsumerKey, java.lang.String oauthConsumerSecret)` |
    `SignatureCalculator​(java.lang.String oauthToken, java.lang.String oauthTokenSecret, java.lang.String oauthConsumerKey, java.lang.String oauthConsumerSecret)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addEmptyFields​(Form form)` |
    `java.lang.String` | `calculateSignature​(JID to, Form form)` | Calculate signature of given form.
    `protected static java.lang.String` | `escape​(java.lang.String s)` |
    `java.lang.String` | `getOauthConsumerKey()` |
    `java.lang.String` | `getOauthConsumerSecret()` |
    `java.lang.String` | `getOauthToken()` |
    `java.lang.String` | `getOauthTokenSecret()` |
    `protected byte[]` | `h​(byte[] data)` |
    `protected static byte[]` | `hmac​(javax.crypto.SecretKey key, byte[] data)` |
    `boolean` | `isMethodSupported​(java.lang.String fOauthSignatureMethod)` |
    `protected javax.crypto.SecretKey` | `key​(byte[] key)` |
    `protected java.lang.String` | `randomString()` |
    `void` | `setOauthConsumerKey​(java.lang.String oauthConsumerKey)` |
    `void` | `setOauthConsumerSecret​(java.lang.String oauthConsumerSecret)` |
    `void` | `setOauthToken​(java.lang.String oauthToken)` |
    `void` | `setOauthTokenSecret​(java.lang.String oauthTokenSecret)` |
    `void` | `sign​(JID to, java.lang.String nonce, long timestamp, Form form)` | Sign given Form.
    `void` | `sign​(JID to, Form form)` | Sign given form with current time.

    - ### 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 java.lang.String SUPPORTED_TYPE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SignatureCalculator

          public SignatureCalculator()

    - #### SignatureCalculator

          public SignatureCalculator​(java.lang.String oauthConsumerKey,
                                     java.lang.String oauthConsumerSecret)

    - #### SignatureCalculator

          public SignatureCalculator​(java.lang.String oauthToken,
                                     java.lang.String oauthTokenSecret,
                                     java.lang.String oauthConsumerKey,
                                     java.lang.String oauthConsumerSecret)

  - ### Method Detail

    - #### escape

          protected static java.lang.String escape​(java.lang.String s)

    - #### hmac

          protected static byte[] hmac​(javax.crypto.SecretKey key,
                                       byte[] data)
                                throws java.security.NoSuchAlgorithmException,
                                       java.security.InvalidKeyException

      Throws:
        `java.security.NoSuchAlgorithmException`
        `java.security.InvalidKeyException`

    - #### addEmptyFields

          public void addEmptyFields​(Form form)

    - #### calculateSignature

          public java.lang.String calculateSignature​(JID to,
                                                     Form form)
                                              throws java.security.InvalidKeyException,
                                                     java.security.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:
        `java.security.InvalidKeyException`
        `java.security.NoSuchAlgorithmException`

    - #### getOauthConsumerKey

          public java.lang.String getOauthConsumerKey()

      Returns:
        the oauthConsumerKey

    - #### setOauthConsumerKey

          public void setOauthConsumerKey​(java.lang.String oauthConsumerKey)

      Parameters:
        `oauthConsumerKey` - the oauthConsumerKey to set

    - #### getOauthConsumerSecret

          public java.lang.String getOauthConsumerSecret()

      Returns:
        the oauthConsumerSecret

    - #### setOauthConsumerSecret

          public void setOauthConsumerSecret​(java.lang.String oauthConsumerSecret)

      Parameters:
        `oauthConsumerSecret` - the oauthConsumerSecret to set

    - #### getOauthToken

          public java.lang.String getOauthToken()

      Returns:
        the oauthToken

    - #### setOauthToken

          public void setOauthToken​(java.lang.String oauthToken)

      Parameters:
        `oauthToken` - the oauthToken to set

    - #### getOauthTokenSecret

          public java.lang.String getOauthTokenSecret()

      Returns:
        the oauthTokenSecret

    - #### setOauthTokenSecret

          public void setOauthTokenSecret​(java.lang.String oauthTokenSecret)

      Parameters:
        `oauthTokenSecret` - the oauthTokenSecret to set

    - #### isMethodSupported

          public boolean isMethodSupported​(java.lang.String fOauthSignatureMethod)

    - #### sign

          public void sign​(JID to,
                           Form form)
                    throws java.security.InvalidKeyException,
                           java.security.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:
        `java.security.InvalidKeyException`
        `java.security.NoSuchAlgorithmException`

    - #### sign

          public void sign​(JID to,
                           java.lang.String nonce,
                           long timestamp,
                           Form form)
                    throws java.security.InvalidKeyException,
                           java.security.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:
        `java.security.InvalidKeyException`
        `java.security.NoSuchAlgorithmException`

    - #### h

          protected byte[] h​(byte[] data)
                      throws java.security.NoSuchAlgorithmException

      Throws:
        `java.security.NoSuchAlgorithmException`

    - #### key

          protected javax.crypto.SecretKey key​(byte[] key)

    - #### randomString

          protected java.lang.String randomString()