# Crypto Module in DataWeave

Author: Manish Prabhu

**Introduction:**

This module in DataWeave provides some functions that can be used to perform encryption (hash) on the message in order to achieve security of the message. This module is having some of the common algorithms support such as MD5, SHA etc.

In order to use this module, you must import dw::crypto module. There are five main functions present in this module.

#### 1) HMACBinary (Binary, Binary, String)

This function has three parameters. The first two parameters are the binary parameters i.e. a key & a message. The third parameter is the optional String parameter i.e. the name of the hashing algorithm. By default, the name of this algorithm is HmacSHA1. For example, if you want to encrypt the message “manish” with a key “abcd” then you should write this function as:

HMACBinary(“abcd” as Binary, “manish” as Binary)

#### 2) HMACWith (Binary, Binary, String)

This function has three parameters. First two parameters are the binary parameters i.e. a key & a message. Third parameter is optional String parameter i.e. the name of the hashing algorithm. By default, the name of this algorithm is HmacSha1. Other possible values for the third parameter are:HmacSHA256 & HmacSHA512. For example, if you want to encrypt the message “manish” with a key “abcd” then you should write this function as:

HMACWith(“abcd” as Binary, “manish” as Binary)

Alternatively, you can add HmacSHA256 or HmacSHA512 as third parameter.

#### 3) MD5 (Binary)

This function is used to compute MD5 hash of the given message. It will take binary message as input & it will convert the encrypted message into a hexadecimal lowercase string. For example, if you want to encrypt the message “manish” then you can write:

MD5(“manish” as Binary)

#### 4) SHA1 (Binary)

This function is used to compute SHA1 hash of the given message. It will take binary message as input & it will convert the encrypted message into a hexadecimal lowercase string. For example, if you want to encrypt the message “manish” then you can write:

SHA1(“manish” as Binary)

#### 5) hashWith (Binary, String)

This function is used to compute hash on a given binary string with the specified algorithm. The default algorithm is SHA-1. For example, if you want to encrypt the message “manish” then you can write:

hashWith(“manish” as Binary)

There are six options available for second parameter: MD2, MD5, SHA-1, SHA-256, SHA-384, SHA-512

Reference: **https://docs.mulesoft.com/mule-runtime/4.2/dw-crypto**