HashLib - Cryptographic hashes in pure Lua

Have to agree with builderboy here, bird boy, Base64 is encoding, something like MD5 is hashing.

2 Likes

I have no idea why you assumed that I said “base64 encoding is hashing”, I know what hashing is…
Also I’m not wally… @NeoInversion

and I currently have no use for hashing

1 Like

Can this module be used to encrypt then decrypt string messages or just hashing?

First post only lists hashing algorithms, not any encryption ones.

It’s HashLib, not EncryptLib.

Cryptographic hashing, by definition, has to be a one way function. No decryption possible. If you could decrypt a hash, then it’s a cracked algorithm and is totally insecure.

2 Likes

Update:

@howmanysmaII went ahead and restructured the module to be easier to read for those of you who are curious, as well as getting it even faster than it already was. She’s truly incredible. Achieving outstanding speed while somehow improving readability is not common.

The latest version is published to the Roblox model.

https://www.roblox.com/library/4544052033/HashLib

5 Likes

Pretty epic module, I’m excited to see what will happen with this however a question have arisen:

  • Would it be reasonable to hash leaderstats (using this module) and send them to an external Database?

Performance wise? Sure.
But why would you be doing that?

I’m interested in knowing why he would as well.

What can be a good use for it?

1 Like

The Game Analytics SDK uses it now, which is a good example of the use of it.

1 Like

Yo, I’m glad you decided to make this because I have a desire to tinker with cryptography! Sent you a friend request on Roblox so I don’t forget to credit you if anything comes of it. Thanks BB and HMS

I don’t think he accepts friend requests from random people. He’s a pretty busy guy. You’d an credit him in the description of your game without friending him.

Thanks for being his spokesman. I was just kidding! How do I decrypt the hash spokesman? I’m hardly random, just keeping the thread alive lol but seriously! How do I reverse the hash back into what it was? People I don’t know are always telling me what to do! shameful.

As stated previously, it is not meant to be decoded.

This is because it is not intended to encrypt/decrypt data for, say, communicating with a remote server but for use to store credentials (such as passwords) instead of the raw string i.e. If you have a password in your game, then instead of doing

local password: string = "password123"

which could potentially be discovered, ruining the point of a password you can do

local password: string = "ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f"

and then you can check the password by converting the input using the same hash function, for example:

local hashLib = require(script.HashLib)
local password: string = "ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f"
local inputBox: TextBox

inputBox:GetPropertyChangedSignal("Text"):Connect(function()
	local hashedString: string = HashLib.sha256(inputBox.Text) -- Doesn't matter which algorithm, so long as it is the same as the pre-defined variable
	if hashedString == password then
		-- Correct password
	else
		-- Wrong password
	end
end)

Edit: I know this is 3 months after you posted but I only looked at this module now and figured it might still be useful.
Edit2: Came back to change code to Luau style guide format.

2 Likes

I appreciate your reply. I find this information very useful as it goes hand in hand with block chaining but the password scenario is even sweeter!

how to un-hash a hashed strings into a proper word using this module?

See boatbomber’s, buildthomases, and my own reply. You cannot “decrypt” a checksum (hashed text) because it is never encrypted. The whole point of hash functions are to create a deterministic checksum, that cannot be converted back (i.e. The hash function has pre-image resistance - given h(x) it should be infeasible to determine x).

3 Likes

I suggest you upload another variant of this as a Github Repository for people who wish to use this externally and from an official source.

Was just searching for this on Wally since I had HashLib vendored in a project I’m a collaborator on. Now that I know this exists and that it’s on Wally, I will be switching all my other hashing implementations over to HashLib. Nice to know this is available!

Super happy with this, it provides a wide range of hashing functions and looks to be highly performant too! My go-to module supports only SHA256 and I don’t dare find out if it’s really unoptimised. If anyone wants a use case, I use hashing to enforce the server being the only machine allowed to connect players to other places in an experience as the option is not natively provided.

Best part is that there’s no colon syntax on the exported functions so this works well with import destructuring when I’m only concerned about using one hashing method.

HashLib on Wally

1 Like