PostgreSQLの機能にpgcryptという暗号関数を提供するライブラリがある
CREATE TEMPORARY FUNCTION decrypt(_text STRING) RETURNS STRING LANGUAGE js AS """ if (_text === null) {return _text} let base64_text = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(_text)) let key = CryptJS.enc.Utf.parse('PASSWORD\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000\\u0000') let iv = CryptoJS.enc.Utf8.parse('') let options = { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }; let _decrypt = CryptoJS.AES.decrypt(base_text, key, options); return _decrypt.toString(CryptoJS.enc.Utf8); """ OPTIONS (library="gs://xxxxxxxxx/crypto-js-4.1.1/crypto-js.js"); SELECT decrypt(substring('\\xba9a0a4189f691d761c431c89f42e319', 3));