Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does base64_encode() Values for Same String Differ?

I want to use a column that contains the string encoded with base64_encode() function as primary key. But I couldn't get to learn that if same string gets different values when encoded with base64_encode().

Should I check the key existence with using encoded string in sql queries or should I get all values from DB and decode them one by one to see if that key exist? That depends on knowing if base64_encode() function always creates the same output for given string. Does it?

Thanks in advance.

like image 465
kubilay Avatar asked Jan 08 '13 21:01

kubilay


2 Answers

Yes, the function base64_encode() always produces the same output for a given string. This is called deterministic function or deterministic algorithm.

http://en.wikipedia.org/wiki/Deterministic_algorithm

like image 162
Alen Oblak Avatar answered Sep 18 '22 00:09

Alen Oblak


base64 encoding always encodes data the same way, note that original encoding of string can yield in different base64 encoding.

Why on earth anyone would use a base64 encoded strings as PK beats me though

like image 28
Peter Hagström Avatar answered Sep 21 '22 00:09

Peter Hagström