Skip to content

Instantly share code, notes, and snippets.

@hishnash
Created April 4, 2017 15:30
Show Gist options
  • Save hishnash/638f2a669c6480acce58181d74fd7a41 to your computer and use it in GitHub Desktop.
Save hishnash/638f2a669c6480acce58181d74fd7a41 to your computer and use it in GitHub Desktop.
.. dv:: HMAC Signature
    :keywords hmac

    .. dvvis:: Visual

        .. figure:: /Images/encoding_crypto/HMACDynamicValue.png

            A Dynamic Value providing `HMAC <https://en.wikipedia.org/wiki/Hash-based_message_authentication_code>`_ keyed hash function (`Message authentication code (MAC) <https://en.wikipedia.org/wiki/Message_authentication_code>`_).

    .. dvspec:: Code
        :identifier: com.luckymarmot.HMACDynamicValue

        .. arg:: input
            :type: DynamicString

            Text input to be hashed.

        .. arg:: key
            :type: DynamicString

            Secret cryptographic key to be used.

        .. arg:: algorithm
            :type: number
            :default: ``0`` (MD5)

            Cryptographic hash function to be used (0: MD5, 1: SHA1, 2: SHA224, 3: SHA256, 4: SHA384, 5: SHA512).

        .. arg:: encoding
            :type: string
            :default: ``Base64``

            Encoding (Base64, Hexadecimal)

        .. arg:: uppercase
            :type: bool
            :default: ``false``

            Whether text output should be in uppercase.

        .. code-block:: javascript

            function evaluate(context){
                var dv = new DynamicValue('com.luckymarmot.HMACDynamicValue', {
                    'input': 'Hello World!',
                    'key': 'supersecretkeynobodyknows',
                                    'algorithm': 1 /* SHA1 */
                });
                return dv.getEvaluatedString();
            };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment