What are some potential pitfalls of using custom encryption algorithms in PHP instead of established methods like mycrypt?

Using custom encryption algorithms in PHP instead of established methods like mycrypt can lead to security vulnerabilities and weaknesses. Established encryption methods like mycrypt have undergone rigorous testing and scrutiny by security experts, making them more reliable and secure. It is recommended to use established encryption libraries like mycrypt to ensure the security of your data.

// Using established encryption method (example using mycrypt)
$plaintext = 'Hello, world!';
$key = 'secretkey';
$method = 'aes-256-cbc';

$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$ciphertext = openssl_encrypt($plaintext, $method, $key, 0, $iv);
$decrypted = openssl_decrypt($ciphertext, $method, $key, 0, $iv);

echo "Ciphertext: $ciphertext\n";
echo "Decrypted: $decrypted\n";