md5 in bigquery
The =
are due to the base64's padding. Nevertheless and according to the documentation, the output should be bytes, but instead the output is a base64 string. You could check this with the following query:
SELECT MD5("Hello World") AS MD5,TO_HEX(MD5("Hello World")) AS BYTES,TO_BASE64(FROM_HEX(TO_HEX(MD5("Hello World")))) as BASE64
With the following output:
Row |MD5 |BYTES |BASE64
1 |sQqNsWTgdUEFt6mb5y4/5Q== |b10a8db164e0754105b7a99be72e3fe5 |sQqNsWTgdUEFt6mb5y4/5Q=
You need to use TO_HEX to get the representation you want as md5 returns BYTES
and you need strings:
TO_HEX: Converts a sequence of BYTES into a hexadecimal STRING. Converts each byte in the STRING as two hexadecimal characters in the range (0..9, a..f).
select TO_HEX(md5('123456')) as hashed
returns:
e10adc3949ba59abbe56e057f20f883e