<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
function encryptCode($data){
return mcrypt_encrypt( MCRYPT_DES , '12345678' , $data , 'cbc' ,'87654321');
}
function decryptCode($data){
return mcrypt_decrypt( MCRYPT_DES , '12345678' , $data , 'cbc' ,'87654321');
}
$id = 'Q2JmDpmqjNmGT4FJ2EkXXITOgc31ZA52';
$base64Decoded = base64url_decode($id);
$decrypted = decryptCode($base64Decoded);
print_r($decrypted."\n");
print_r("\n\n");
# Make the new plaintext string
$toAdd = 'hellothere';
$additionalCipherText = encryptCode($toAdd);
$additionalEncoded = base64url_encode($additionalCipherText);
print_r("Additional cipher text:".$additionalEncoded."\n");
print_r("\n\n");
# Concatenate the plaintext and encrypt
$plaintext = $decrypted.$toAdd;
$cipherText = encryptCode($plaintext);
$base64Encoded = base64url_encode($cipherText);
print_r(" New cipher text: ".$base64Encoded."\n");
print_r("Original cipher text: ".$id.$additionalEncoded."\n");
# Try the reverse order
$plaintext = $toAdd.$decrypted;
$cipherText = encryptCode($plaintext);
$base64Encoded = base64url_encode($cipherText);
print_r(" New cipher text: ".$base64Encoded."\n");
print_r("Original cipher text: ".$additionalEncoded.$id."\n");
preferences:
23.02 ms | 409 KiB | 5 Q