The sha1 string function is used to calculate the SHA-1 (Secure Hash Algorithm 1) hash of a string value.
It is mainly used for converting a string into 40-bit hexadecimal number, which is so secured.
"SHA-1" produces a 160-bit output called a message digest.
php developer Syntax :
string source- defines the input string.
raw_output – The raw output is like a Boolean function that is: If TRUE , it sets raw 20-character binary format. If FALSE (default) then it sets raw 40-character hex number format.
Advantage of Using sha-1 function :
When you use the sha1 function at first time while running the string it will generate a different hash value for the string. If you run it again and again the hash vale for the string will be different every time.
Produces a longer hash value than MD5
Provides a one-way hash
Disadvantage of Using sha-1 function :
Sha-1 algorithm is the slower computational algorithm than the MD5 algorithm.
Has known security vulnerabilities
php 7 Sample Code : sample php program
php program Code Explanation :
In this echo statement we call the “sha1” string function that will be used for calculating the hash function value for the term “wikitechy” .
In this echo statement we call the “sha1” string function that will be used for calculating the hash function value of the term “wikitechy “and here we use the Boolean function set as true so the raw output of the encrypted text has been displayed only the 20 characters in your browser.
php coding Sample Output :
Here in this output the term “wikitechy” was encrypted using the sha1 algorithm which encrypts by setting the raw 40-character hex number format.
Similarly, over here the term “wikitechy” was encrypted using the sha1 algorithm since we setted the argument value set as “true” so the encryption was done in 20-character binary format.