- bin2hex: documentation ( source)
- str_repeat: documentation ( source)
<?php
echo bin2hex(
openssl_encrypt(
/* Message: */
"The quick brown fox jumps over the lazy dog",
/* Cipher algorithm and block mode: */
'aes-128-ctr',
/* Encryption key: (don't use weak keys like this ever, it's just an example!): */
"\x01\x02\x03\x04"."\x05\x06\x07\x08" . "\x09\x0a\x0b\x0c" . "\x0d\x0e\x0f\x10",
/* Constant that means "don't encode": */
OPENSSL_RAW_DATA,
/* Initialization Vector or Nonce -- don't ever actually use all NULL bytes: */
str_repeat("\0", 16)
// This is a really bad way to generate a nonce or IV.
// See how it's done here: http://stackoverflow.com/a/30189841/2224584
)
);