0

My client uses a 3rd party vendor to store contacts and send promotional emails. All of the emails drive the user to various landing pages on their website. occasionally there is a need for personalization where the landing page may display the user's name, email address and/or other saved preferences. In the emails, we have the ability to merge fields, which I am currently using to pass their email address (encrypted) through the url to the landing page (ex www.example.com/landing-page/?UID=NGNVdGM2T3AvSo00UWkyQnUyeUNxczRRaXV2cHprdzRNUXV6S2ujoEZYakNteTAzRWZuekR4RmFReStXckE9PQ==).

If the page requires more of the user's info, the email address is used as the primary key in the vendor's API. So I may make a request to an endpoint such as (www.example-vendor-api.com/ACCOUNT_NUMBER/member) with a payload of { email: user@some-company.com } and the public and private API keys passed as Authentication header.

Right now, I have a custom field in the vendor database called uid. Any time someone completes a form and is added to that database, I encrypt their email address which is then stored in that column.

I know very little about this so I'm trying to find out if my encryption/decryption method offers adequate security or if a scenario such as this requires an entire library such as Pixelfck/SymmetricEncryption (this was recommended to me and looks fairly easy to use).

Anyway, I'm using PHP's openssl_* functions with aes-256-gcm cipher with a static key stored on our server and a pseudo-randomly generated IV. here's the PHP I got largely from this post.

function encrypt($encryptionKey, $data) {
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-gcm'));
    $encrypted = openssl_encrypt($data, 'aes-256-gcm', $encryptionKey, OPENSSL_RAW_DATA, $iv, $tag);
    return bin2hex($iv . $tag . $encrypted);
}

function decrypt($encryptionKey, $data) {
    $c = hex2bin($data);
    $ivlen = openssl_cipher_iv_length($cipher="AES-256-GCM");
    $iv = substr($c, 0, $ivlen);
    $tag = substr($c, $ivlen, $taglen=16);
    $ciphertext_raw = substr($c, $ivlen+$taglen);
    return openssl_decrypt($ciphertext_raw, 'aes-256-gcm', $encryptionKey, OPENSSL_RAW_DATA, $iv, $tag);
}

If anyone could comment on the level of security this provides in relation to the use case and/or if I should be using an existing library, I'd be most appreciative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.