Hashing text using Crypto.Hash or something similar

Hello Everyone,

I’m trying to create a method called generateHashedPassword() that accepts a string and returns the SHA512 hash of that string. For some reason. the compiler is throwing a syntax error no matter what I try. This is the code I have:

Dim hashedPassword as String

hashedPassword = Crypto.SHA512(password)
return hashedPassword

That throws an error. So I try this:

hashedPassword = str(Crypto.SHA512(password))
return hashedPassword

and it still throws an error.

The example in the docs shows that this might work:

Dim hashedPassword as String
hashedPassword = Crypto.Hash(password, Crypto.Algorithm.SHA512)
return hashedPassword

Doesn’t look like that works. So, I’m stuck… How the heck do I actually hash text using the Crypto API?

Thanks!
Dave

What error are you getting?

When I do

hashedPassword = Crypto.SHA512(password)

I’m told the password doesn’t exist even though I am indeed specifying password As String in the input parameters for the method.

When I try

Function generatePasswordHash(password) As String
// Return the SHA512 hash of the users password.

Dim hashedPassword as String

hashedPassword = Crypto.HashAlgorithms.SHA512(password)

End Function

I get told that the item doesn’t exist but with the Crypto.HashAlgorithm part highlighted.

If this is how the method is declared, then this is the error. You must specify the type as well as the name of the parameter:

Function generatePasswordHash(password AS STRING) As String