Skip to content
Advertisement

Generating crypt() sha512 hashes in Go

I am working on my authorization module in GoLang. Before we used PHP5 with the crypt function. The hash was generated like SHA-512:

JavaScript

And stored like that in the database. But now I need make it work also in GoLang. I have searched on Google and tried different things, such as:

JavaScript

But all generate different things. Who can help us further?

We want validate and create hashes like the php version.

Thanks in advance.

Advertisement

Answer

The osutil library at https://github.com/kless/osutil has support for all crypt() hash types.

Your password hash can be produced with the following php code:

JavaScript

This code produces the following hash:

JavaScript

This can be reproduced in Go like this:

JavaScript

When run, it also produces the correct hash:

JavaScript

I hope this answers your question.

While implementing this please note that only 16 characters are used from the salt, so the same hash is returned for the salt usesomesillystri. Make sure that you choose random salts in the production code.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement