Tom
Tom

Reputation: 9643

php base64_encode without the = sign

I'm using the base64_encode function to hash strings. The strings must be a-zA-Z0-9 and sometimes base64_encode outputs the = sign at the end (sometimes twice).

What is the most efficient way to alter the base64_encode function (override?) to omit the = signs?

Upvotes: 0

Views: 3673

Answers (2)

Jon
Jon

Reputation: 437326

The possible =s at the end are required if you want to decode the value later. Also, the character set a-zA-Z0-9 has only 62 values and thus a base-64 encoded value can never fit inside it.

Update: If you need to hash strings, why not use a hash function? md5 should be a good go-to solution unless the application is security-sensitive, in which case a stronger hash (sha1 or better) should be used.

Upvotes: 5

fire
fire

Reputation: 21531

As Jon said you need the = to decode it later but from what you say you don't need to do that, in which case your better off using md5 instead, this will give you a 32 character A-F/0-9 string.

Upvotes: 1

Related Questions