· 9 years ago · Jan 27, 2017, 07:52 PM
1$secret_key = 'e6aeee1c80c231bf724b31d3c4cc77dd';
2$string = 'This is a string to encode';
3$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
4
5// this will be sent with the first redirect...
6$state = rawurlencode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $secret_key, $string, MCRYPT_MODE_CBC, $iv));
7
8// .. this will be received when the client is redirected back here
9// in another HTTP request
10$decrypted_string = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $secret_key, rawurldecode($state), MCRYPT_MODE_CBC, $iv);
11
12var_dump($decrypted_string); // Outputs: "This is a string to encode"
13
14$secret_key = 'e6aeee1c80c231bf724b31d3c4cc77dd';
15$string = 'This is a string to encode';
16$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
17
18// this will be sent with the first redirect...
19$state = rawurlencode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $secret_key, $string, MCRYPT_MODE_CBC, $iv));
20
21$secret_key = 'e6aeee1c80c231bf724b31d3c4cc77dd';
22$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
23
24$decrypted_string = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $secret_key, rawurldecode($state), MCRYPT_MODE_CBC, $iv);
25
26// Outputs: "�|% <�-��+^�%6��7�rY��^�"