PHP- Sha1 Function
Total Page:16
File Type:pdf, Size:1020Kb
|PHP PHP- sha1 Function 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. Syntax: string sha1 ( string source [, bool raw_output]); Syntax Explanation: 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. 1. Produces a longer hash value than MD5 2. Collision Resistant 3. Widespread Use 4. Provides a one-way hash Facebook.com/wikitechy twitter.com/WikitechyCom © Copyright 2016. All Rights Reserved. |PHP Disadvantage of Using sha-1 function: 1. Sha-1 algorithm is the slower computational algorithm than the MD5 algorithm. 2. Has known security vulnerabilities Sample code: <!DOCTYPE> <html> <body> <?php echo sha1('wikitechy'); echo "<br>"; echo sha1('wikitechy',TRUE); ?> </body> </html> Facebook.com/wikitechy twitter.com/WikitechyCom © Copyright 2016. All Rights Reserved. |PHP 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 Facebook.com/wikitechy twitter.com/WikitechyCom © Copyright 2016. All Rights Reserved. |PHP output of the encrypted text has been displayed only the 20 characters in your browser. 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. Facebook.com/wikitechy twitter.com/WikitechyCom © Copyright 2016. All Rights Reserved. .