I'm using php to read a file for a $string
, it has some variable words that I need to find and replace with others, ie I need to get these variables, encrypt them with AES and write back where they were, making a replace
.
The variables do not have the same name , and they see after the parameter cmd=
, the amount of them can vary.
Sample file with variables:
Inicio
texto=nome?cmd=0a7-5.ext
data...
texto=nome?cmd=12345.ext
data...
texto=nome?cmd=abcd.ext
The value to be replaced is the encrypted variable itself with the following AES:
//fnEncrypt("0a7-5", "1234567890123456");
function fnEncrypt($sValue, $sSecretKey)
{
return rtrim(
base64_encode(
mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$sSecretKey, $sValue,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(
MCRYPT_RIJNDAEL_256,
MCRYPT_MODE_ECB
),
MCRYPT_RAND)
)
), "Inicio
texto=nome?cmd=dxZIKbLDEtI/m81cEGnB+dVbmy1C+fcIxmeBGHpyYY0=
data...
texto=nome?cmd=+FFzyIqAENF13PnEj5XqpHYlMD2u08uHmWK7HYDyPos=
data...
texto=nome?cmd=cTySfjmfN85GgcWS3aVHSwExC2ZBldBqh9xJq9ndAmc=
"
);
}
What is expected:
Inicio
texto=nome?cmd=0a7-5.ext
data...
texto=nome?cmd=12345.ext
data...
texto=nome?cmd=abcd.ext
How can I replace these variables with their AES-encrypted version, knowing that the number of them and their values are different?