Package tigase.util

## Class Algorithms

- java.lang.Object
- - tigase.util.Algorithms

-     public class Algorithms
      extends java.lang.Object

  Describe class Algorithms here. Created: Wed May 4 13:24:03 2005
  Version:
    $Rev$
  Author:
    Artur Hefczyc

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `$main​(java.lang.String[] args)` | Describe `main` method here.
    `static java.lang.String` | `bytesToHex​(byte[] buff)` |
    `static byte[]` | `digest​(java.lang.String id, java.lang.String secret, java.lang.String alg)` |
    `static java.lang.String` | `generateDialbackKey​(java.lang.String originatingServer, java.lang.String receivingServer, java.lang.String secret, java.lang.String streamID)` | Calculates dialback key as decribed in XEP-0185 version 1.0.
    `static java.lang.String` | `hexDigest​(java.lang.String id, java.lang.String secret, java.lang.String alg)` | This method encodes data using digest algorithm described in JEP-0078 documentation.
    `static java.lang.String` | `sha256​(java.lang.String data)` | Calculates SHA-256 hash of given data.

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

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

- - ### Method Detail

    - #### $main

          public static void $main​(java.lang.String[] args)
                            throws java.lang.Exception

      Describe `main` method here.
      Parameters:
        `args` - a `String[]` value
      Throws:
        `java.lang.Exception`

    - #### bytesToHex

          public static final java.lang.String bytesToHex​(byte[] buff)

    - #### digest

          public static final byte[] digest​(java.lang.String id,
                                            java.lang.String secret,
                                            java.lang.String alg)
                                     throws java.security.NoSuchAlgorithmException

      Throws:
        `java.security.NoSuchAlgorithmException`

    - #### generateDialbackKey

          public static java.lang.String generateDialbackKey​(java.lang.String originatingServer,
                                                             java.lang.String receivingServer,
                                                             java.lang.String secret,
                                                             java.lang.String streamID)

      Calculates dialback key as decribed in XEP-0185 version 1.0.
      Implemented algorithm (recomended in XEP-0185):

           key = HMAC-SHA256
                 (
                   SHA256(Secret),
                   {
                     Receiving Server, ' ',
                     Originating Server, ' ',
                     Stream ID
                   }
                 )

      Parameters:
        `originatingServer` - the hostname of the Originating Server
        `receivingServer` - the hostname of the Receiving Server
        `secret` - a secret known by the Authoritative Server's network
        `streamID` - the Stream ID generated by the Receiving Server
      Returns:
        string contains HEX encoded dialback key.

    - #### hexDigest

          public static final java.lang.String hexDigest​(java.lang.String id,
                                                         java.lang.String secret,
                                                         java.lang.String alg)
                                                  throws java.security.NoSuchAlgorithmException

      This method encodes data using digest algorithm described in JEP-0078 documentation. As a result you have `String` containing digest data which can be compared with data sent by the user to authenticate him.
      Parameters:
        `id` - a `String` value of some ID value like session ID to concatenate with secret word.
        `secret` - a `String` value of a secret word shared between entites.
        `alg` - a `String` value of algorithm name to use for generating diffest message.
      Returns:
        a `String` value digest message as defined.
      Throws:
        `java.security.NoSuchAlgorithmException` - if an error occurs during encoding digest message.

    - #### sha256

          public static java.lang.String sha256​(java.lang.String data)

      Calculates SHA-256 hash of given data.
      Parameters:
        `data` - data to hash
      Returns:
        string contains HEX encoded SHA-256 of data.