create a sha512 hash from a string in php

To create a SHA512 hash from a string in PHP, you can use the hash() function with the "sha512" algorithm. Here's an example:

main.php
$string = "Hello, world!";
$hash = hash('sha512', $string);
echo $hash; // Output: 0e5912727da73ca508b4f4b97b22d4db4674f2c35a4964e6348c8cf68040b6b...
150 chars
4 lines

In this example, the $string variable contains the string you want to hash. The $hash variable is set to the result of calling hash('sha512', $string), which generates a SHA512 hash of the input string.

You can use this function to hash sensitive data such as passwords to protect them from hackers. It's also recommended that you use a salt with the hash function to further strengthen the security of the hashed value.

related categories

gistlibby LogSnag