Skip to main content

Hashing Identifiers

Surfside links your records to its identity graph on SHA-256 hashes of email and phone, and on raw mobile device IDs. We never need plaintext contact details. A hash only matches when both sides prepared the input the same way, so this page fixes the preparation once, gives you code that does it, and gives you test vectors to prove your output before the first file ships.

Accepted identifiers​

Each email and phone is sent as two hashes. The first is the form our identity graph indexes. The second is the normalized form that activation and measurement destinations index. Sending both lets one file match everywhere we connect you, with no re-export when a destination is added. For most records the two email hashes are identical.

IdentifierColumnPrepareHash
Email addressemail_sha256Remove all whitespace, then lowercase the whole address. Change nothing else.SHA-256, 64 lowercase hex characters
Email address, normalizedemail_sha256_normalizedAs above, and for gmail.com addresses only, remove dots and anything from + onward in the part before the @.SHA-256, 64 lowercase hex characters
Phone numberphone_sha256Drop any extension, keep digits only, keep the last ten. US and Canada only; empty for any other country.SHA-256, 64 lowercase hex characters
Phone number, E.164phone_sha256_e164+, the country code, then the national number with no trunk zero and no punctuation. Any country.SHA-256, 64 lowercase hex characters
Mobile device IDdevice_idIDFA or GAID exactly as the operating system issued it.None. Send it raw. A hashed device ID cannot be matched.
Client customer IDccidYour own stable identifier for the person. It is the audience key and must not change between files.None
caution

SHA-256 is the only accepted hashing algorithm. MD5 and SHA-1 hashes cannot be matched and will produce zero matches with no error.

Email addresses​

  1. Remove all whitespace. Spaces, tabs and line breaks, at the ends and inside the address.
  2. Lowercase the whole address. Jane@Example.com becomes jane@example.com. We match on the lowercase form.
  3. Hash with SHA-256 and write it to email_sha256. Write the digest as 64 lowercase hex characters with no 0x prefix. Keep plus tags, dots and subdomains exactly as the customer typed them.
  4. For gmail.com addresses only, normalize the part before the @. Remove every dot, and remove the + and everything after it. jane.doe+promo@gmail.com becomes janedoe@gmail.com. Every other domain is left exactly as it was in step 2.
  5. Hash the normalized address with SHA-256 and write it to email_sha256_normalized. For any address that is not gmail.com, this hash is identical to email_sha256.
  6. No address, no hash. Leave both fields empty rather than hashing an empty string.
Other domainsGmail
Input" Jane.Doe+promo@Example.com "" Jane.Doe+promo@Gmail.com"
email_sha256 preparedjane.doe+promo@example.comjane.doe+promo@gmail.com
email_sha256c3374bcfe3572e09f37602e0e179782352c5e117a4a3767824abbaa21bbdef8b5f0d1df1fc49e30424381b57b1d4c73e067772a4267dde043a19b026935602c8
email_sha256_normalized preparedjane.doe+promo@example.comjanedoe@gmail.com
email_sha256_normalizedc3374bcfe3572e09f37602e0e179782352c5e117a4a3767824abbaa21bbdef8bd6117306485ed0e50afab3ac871e98f81699151f30281527d63ff5f233656c69

Phone numbers​

A file holds numbers from one country, which you agree with your Customer Success manager before the first file. That country's code is the one you prefix in step 5.

  1. Drop any extension first. Cut x204, ext. 7 and everything after it before you strip characters, or the extension digits end up inside the number.
  2. Strip every non-digit. Spaces, dashes, dots, parentheses and the plus sign all go.
  3. Remove the country code and any trunk prefix. For the US and Canada, drop a leading 1 so ten digits remain. For other countries, drop the country code if it was typed and then the trunk zero, so 0491 570 006 in Australia becomes 491570006. A US or Canadian number that is not exactly ten digits, or any number with fewer than five, is not usable: leave both fields empty.
  4. US and Canada only: hash the ten digits with SHA-256 and write it to phone_sha256. Write the digest as 64 lowercase hex characters with no 0x prefix. For every other country leave this field empty.
  5. Prefix + and the country code, then hash again. Write that digest to phone_sha256_e164. +1 for the US and Canada, +61 for Australia, +44 for the UK, and so on. The result is at most 15 digits after the +.
US and CanadaOther countries
Input"+1 (415) 555-0132""0491 570 006" (Australia)
phone_sha256 prepared4155550132empty
phone_sha256983c25606b8b0ac842c0bb1b723f3f600de24cd8a792d6e29a7da88d732af0beempty
phone_sha256_e164 prepared+14155550132+61491570006
phone_sha256_e1649e1919ad78a34fd67a84bfbcf2fea14074065517bea32e92924771c3f92e5462858658053d2e122b7d9ddef2f65e42e738e7421be32b7a91df35aeb3e8fcce8f
note

EU data files must not contain phone numbers, hashed or otherwise. Numbers outside the US and Canada match only through phone_sha256_e164.

Hashing examples​

All three reproduce the test vectors above. Verify that before you build anything else.

Python​

import hashlib, re

def sha256(s):
return hashlib.sha256(s.encode()).hexdigest()

def email_hashes(raw):
s = "".join(raw.split()).lower()
if not s:
return "", ""
local, _, domain = s.rpartition("@")
normalized = s
if domain == "gmail.com":
normalized = local.split("+")[0].replace(".", "") + "@gmail.com"
return sha256(s), sha256(normalized)

def phone_hashes(raw, country_code="1"):
number = re.split(r"\s*(?:x|ext)", raw, flags=re.I)[0]
digits = re.sub(r"\D", "", number)
if digits.startswith(country_code) and len(digits) > len(country_code) + 6:
digits = digits[len(country_code):]
national = digits.lstrip("0")
if country_code == "1":
return (sha256(national), sha256("+1" + national)) if len(national) == 10 else ("", "")
if len(national) < 5 or len(country_code) + len(national) > 15:
return "", ""
return "", sha256("+" + country_code + national)

JavaScript​

const { createHash } = require("crypto");
const sha256 = s =>
createHash("sha256").update(s).digest("hex");

const emailHashes = raw => {
const s = raw.replace(/\s+/g, "").toLowerCase();
if (!s) return ["", ""];
const at = s.lastIndexOf("@");
let normalized = s;
if (s.slice(at + 1) === "gmail.com") {
normalized = s.slice(0, at).split("+")[0].replace(/\./g, "") + "@gmail.com";
}
return [sha256(s), sha256(normalized)];
};

const phoneHashes = (raw, countryCode = "1") => {
const number = raw.split(/\s*(?:x|ext)/i)[0];
let digits = number.replace(/\D/g, "");
if (digits.startsWith(countryCode) && digits.length > countryCode.length + 6) {
digits = digits.slice(countryCode.length);
}
const national = digits.replace(/^0+/, "");
if (countryCode === "1") {
return national.length === 10 ? [sha256(national), sha256("+1" + national)] : ["", ""];
}
if (national.length < 5 || countryCode.length + national.length > 15) return ["", ""];
return ["", sha256("+" + countryCode + national)];
};

Snowflake SQL​

with prepared as (
select
ccid,
nullif(lower(regexp_replace(email, '\\s', '')), '') as email_prepared,
regexp_replace(regexp_replace(phone, '\\s*(x|ext).*$', '', 1, 0, 'i'), '[^0-9]', '') as phone_digits_raw,
'1' as country_code -- one country per file, agreed before the first file
from customers
),
phone as (
select
ccid,
email_prepared,
country_code,
ltrim(iff(startswith(phone_digits_raw, country_code) and len(phone_digits_raw) > len(country_code) + 6,
substr(phone_digits_raw, len(country_code) + 1), phone_digits_raw), '0') as national
from prepared
),
normalized as (
select
ccid,
email_prepared,
iff(split_part(email_prepared, '@', -1) = 'gmail.com',
replace(split_part(split_part(email_prepared, '@', 1), '+', 1), '.', '') || '@gmail.com',
email_prepared) as email_normalized,
iff(iff(country_code = '1', len(national) = 10, len(national) >= 5 and len(country_code) + len(national) <= 15),
national, null) as national,
country_code
from phone
)
select
ccid,
sha2(email_prepared, 256) as email_sha256,
sha2(email_normalized, 256) as email_sha256_normalized,
sha2(iff(country_code = '1', national, null), 256) as phone_sha256,
sha2('+' || country_code || national, 256) as phone_sha256_e164
from normalized

Before you send​

  • Every hash is exactly 64 lowercase hex characters. No 0x prefix, no uppercase hex, no base64.
  • Your output for the test vectors matches this page character for character.
  • Send all four hash columns on every record that has an email and a phone. We match on any of them and email wins when they disagree.
  • An unknown value is an empty cell. Never a placeholder, never the hash of an empty string.
  • No plaintext email or phone anywhere in the file, including in free-text columns.
  • Column headers and the ccid stay identical across every file you send.
  • UTF-8, one record per line, comma delimited, named Partner-YYYYMMDD-dataset.csv, gzipped if large. See Batch Upload File Format for the full file contract.
  • No salting, no peppering, no hashing a hash. Our join is an exact string match, so any of these produce zero matches and no error.

Summary and best practices​

One rule for every file: prepare the value exactly as this page describes, hash it once with SHA-256, send lowercase hex or nothing. Everything else is about keeping that rule stable over time.

  • Hash inside your export job. Put the preparation code in the pipeline that writes the file, not in a spreadsheet step. Every file then comes from the same code path.
  • Keep plaintext on your side. Only the hashes and your customer ID leave your systems. Keep your own mapping from ID to person so you can act on what comes back.
  • Send every identifier you hold. A record with both an email and a phone hash matches more often than either alone. Never drop a record because one is missing.
  • Re-run the test vectors on every change. A new library version or a refactor can shift output by one character, and one character is a zero match rate.