1. Perl
  2. Module
  3. here

Digest::SHA - Calculate the digest value by SHA

You can use the Digest::SHA module to find various SHA values. Use the following function to find the SHA-1 value.

# Loading modules and importing functions
use Digest::SHA 'sha1_hex';

You can use the sha1_hex function to get the SHA-1 value as a 40-digit hexadecimal string.

# SHA-1 Find the value
my $sha1_sum = sha1_hex'alkeiop2lkj39';

The result is a 40-digit hexadecimal number like this:

# SHA-1 value (obtained as a hexadecimal string)
20b07a8050be5dd980b1c17109fbbffaf3194498

Digest::SHA FAQ

Q. Simply put, what is SHA?

A. It is one of the functions that creates "a value that is very difficult to guess the original value" from "a certain value". It is used to check if the file is corrupted (even if the file is slightly corrupted, it can be checked by the different SHA value), or it is used for digital signatures. SHA is harder to guess than MD5, which has the same functionality. You can use Digest::MD5 module to find the MD5 value.

Q. Is it possible to get SHA-1 values in other formats?

A. Yes you can. You can use the sha1 function to get the SHA-1 value in binary format, and the sha1_base64 function to get the SHA-1 value in base64 format.

Q. In addition to SHA-1, there are high-strength SHA-256, SHA-384, SHA-512, etc. Can I use them?

A. Yes you can. It has the following functions:

# Binary format
sha1
sha224
sha256
sha384
sha512

# Hexadecimal string
sha1_hex
sha224_hex
sha256_hex
sha384_hex
sha512_hex

# base64 format
sha1_base64
sha224_base64
sha256_base64
sha384_base64
sha512_base64

Related Informatrion