authen
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
fn_decode_precheckin_url
Parameters
Name
Type
Mode
encoded_param
text
IN
Definition
DECLARE encryption_key text := 'fromas-cloud-precheckin'; decoded_bytes bytea; derived_key bytea; initialization_vector bytea; encrypted_bytes bytea; decrypted_bytes bytea; decrypted_text text; begin -- Decode Base64 to bytes decoded_bytes := decode(encoded_param, 'base64'); -- Extract IV (first 16 bytes) and encrypted data initialization_vector := substring(decoded_bytes from 1 for 16); encrypted_bytes := substring(decoded_bytes from 17); -- Derive the same key derived_key := digest(encryption_key, 'sha256'); -- Validate key length IF octet_length(derived_key) != 32 THEN RAISE EXCEPTION 'Key derivation failed: invalid key length'; END IF; -- Decrypt using AES-256-CBC decrypted_bytes := decrypt_iv(encrypted_bytes, derived_key, initialization_vector, 'aes-cbc/pad:pkcs'); -- Convert back to text and then to JSON decrypted_text := convert_from(decrypted_bytes, 'UTF8'); RETURN decrypted_text::jsonb; END;