How to Calculate and Validate the Checksum Using Mule 4

Sudheerkumar
Another Integration Blog
4 min readAug 8, 2022

--

This post includes:

  • What is a checksum?
  • Factors that can cause an inconsistent checksum number
  • Types of checksum algorithms
  • How to calculate and validate a checksum using Mule 4
  • Installation
  • Demo
  • Conclusion

What is a Checksum?

A checksum is used to determine whether there has been any data tampering or errors during the transmission of data.

Factors That can Cause an Inconsistent Checksum Number

  • Network errors
  • Space constraints
  • Corrupted data or files
  • A third-party involvement during the transmission of data

Types of Checksum Algorithms

Different checksum algorithms produce different results.

  • CRC32
  • MD2
  • MD5
  • SHA_1
  • SHA_256
  • SHA_512

The algorithms listed above are all different hash functions with different buffer sizes (i.e., 128 bits, 160 bits, 256 bits, etc.). As a result, each algorithm will produce a different hash value.

Example:

Consider the scenarios below, where the different algorithms will produce different hash values using the same input data.

MD5:

Input:

{

“message”: “Generate Checksum”

}

Output Hash Value:

“c8452768395403b509b377b0143cab9b”

SHA_256:

Input:

{

“message”: “Generate Checksum”

}

Output Hash Value:

“e3649db56423d752f69a66329199ce426ebc2bcc26d09b7b383d0a70479bcee1”

CRC32:

Input:

{

“message”: “Generate Checksum”

}

Output Hash Value:

“548c2c06”

How to Calculate and Validate a Checksum Using Mule 4

MuleSoft provides cryptography, which assists developers in creating flows for calculating and validating checksums.

Calculate Checksum:

Calculates the checksum of a given data using the hashing algorithm.

Validate Checksum:

Validates the checksum of the data previously calculated using the calculate checksum operation.

Installation:

To use the crypto module, first download the module from the exchange. Click on Search in Exchange -> Search for Cryptography Module -> Select Add >. Then click Finish.

Demo:

Step 1:

The figure below represents the original data that the sender will provide.

Step 2:

The figure below represents the tampered data.

Step 3:

The figure below represents the original data hash value.

Step 4:

The figures below represent the original data checksum flow.

Step 5:

The figures below represent the tampered data checksum flow.

Step 6:

Run the Mule application.

Step 7:

Consider the scenario where the checksum matches.

Input:

The “Calculate Checksum” operation calculates the checksum from the data transmitted. It stores the value as the “Vchecksum” variable.

The “Validate Checksum” operation validates the expected and actual checksum values.

Output:

Step 8:

Consider the scenario where the data is tampered with or there are errors in the data.

Input:

Output:

The “Validate Checksum” throws the following error:

If the expected checksum (provided by the sender) does not match the actual checksum (received by the receiver), it will indicate that there is an error in the data or that there has been third-party data tampering.

Conclusion

This article describes how to generate the hash value, calculate, and validate the checksum in Mule 4.

Thank you for reading my post and I hope it will be helpful.

That’s it for now! See you in the next post!

-Sudheer Kumar N

--

--