Weak cryptography

Weak cryptography

Description

DES, RC4, ECB mode and custom XOR encryption provide inadequate protection for sensitive data.

Potential impact

Weak encryption can expose plaintext or leave message changes undetected.

Remediation

Use authenticated encryption from a vetted library. Have getEncryptionKey() return a securely generated and stored 32-byte AES key. Never reuse an IV with the same key.

Examples

Before

php
<?php
$ciphertext = openssl_encrypt($data, 'des-ecb', $key);

After

php
<?php
$key = getEncryptionKey();
$iv = random_bytes(openssl_cipher_iv_length('aes-256-gcm'));
$ciphertext = openssl_encrypt($data, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag);

The example passes a random IV to aes-256-gcm and receives an authentication tag. On successful encryption, store the IV and tag with the ciphertext. Discard the data if tag verification fails during decryption.

References