I have a table with three columns named: Question, Answer, Hashed. I want to update the Hashed column with the Answer column hashed using sha512.
I've tried to do the update directly from my MySql database using this syntax, but it didn't work:
UPDATE TableName SET Hashed = SHA512(Answer) WHERE Hashed IS NULL
I know the syntax is wrong but not sure why.
Thanks in advance for your help!
R
Give this a shot.
UPDATE TableName SET Hashed=SHA2(Answer, 512) WHERE Hashed IS NULL;
Note that this will only work with MySQL 5.5 onward. For versions before 5.5, you'll have to use application code to hash it (PHP to get all the rows, iterate through and hash $row['answer'] to SHA512, then run the UPDATE commands on each) (Source: http://dev.mysql.com/doc/refman/5.5/en//encryption-functions.html#function_sha2)
I hope this is not too late. Even if, maybe someone else will find out this hint:
UPDATE TableName SET Hashed = ENCRYPT('Answer', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))) WHERE Hashed IS NULL;
What it does, it creates sha-512 hash, with it's schema: $6$
from string 'Answer'
If you are using debian, you may also use mkpasswd
from package libstring-mkpasswd-perl
to generate SHA-512 for you, and update as string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With