BEGIN; CREATE EXTENSION IF NOT EXISTS anon CASCADE; SELECT anon.init(); init ------ t (1 row) -- -- Using the automatic salt and default algorithm -- SELECT anon.hash(NULL) IS NULL; ?column? ---------- t (1 row) SELECT anon.hash('x') = anon.digest('x',anon.get_secret_salt(), anon.get_secret_algorithm()); ?column? ---------- t (1 row) -- -- With a random salt -- SELECT anon.random_hash('abcd') != anon.random_hash('abcd'); ?column? ---------- t (1 row) -- Restore a predifened salt and change the algo SELECT anon.set_secret_salt('4a6821d6z4e33108gg316093e6182b803d0361'); set_secret_salt ---------------------------------------- 4a6821d6z4e33108gg316093e6182b803d0361 (1 row) SELECT anon.set_secret_algorithm('md5'); set_secret_algorithm ---------------------- md5 (1 row) SELECT anon.hash('x'); hash ---------------------------------- 9072b9a6712c6d3924c79488d6ee1c2f (1 row) SELECT anon.set_secret_algorithm('sha512'); set_secret_algorithm ---------------------- sha512 (1 row) SELECT anon.hash('x'); hash ---------------------------------------------------------------------------------------------------------------------------------- ef50c6f79ba70b3eb96cded76956ef59f9aa2ff0365b7ccec6d128d21bc52be21236b72a90a77c9147b542eaacbe90a7134bc4477d5774ba7ac1443764147b15 (1 row) -- digest SELECT anon.digest(NULL,'b','sha1') IS NULL; ?column? ---------- t (1 row) SELECT anon.digest('a',NULL,'sha1') IS NULL; ?column? ---------- t (1 row) SELECT anon.digest('a','b',NULL) IS NULL; ?column? ---------- t (1 row) SELECT anon.digest('a','b','md5') = '187ef4436122d1cc2f40dc2b92f0eba0'; ?column? ---------- t (1 row) SELECT anon.digest('a','b','sha1') = 'da23614e02469a0d7c7bd1bdab5c9c474b1904dc'; ?column? ---------- t (1 row) SELECT anon.digest('a','b','sha224') = 'db3cda86d4429a1d39c148989566b38f7bda0156296bd364ba2f878b'; ?column? ---------- t (1 row) SELECT anon.digest('a','b','sha256') = 'fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603'; ?column? ---------- t (1 row) SELECT anon.digest('a','b','sha384') = 'c7be03ba5bcaa384727076db0018e99248e1a6e8bd1b9ef58a9ec9dd4eeebb3f48b836201221175befa74ddc3d35afdd'; ?column? ---------- t (1 row) SELECT anon.digest('a','b','sha512') = '2d408a0717ec188158278a796c689044361dc6fdde28d6f04973b80896e1823975cdbf12eb63f9e0591328ee235d80e9b5bf1aa6a44f4617ff3caf6400eb172d'; ?column? ---------- t (1 row) ROLLBACK;