PHP code, PHP provides many things, you can use functions directly, but PHP currently only knows the filling mode ZeroPadding, so other languages can only follow it:
- $privateKey = "1234567812345678";
- $iv = "1234567812345678";
- $data = "Test String";
- //Encryption
- $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $privateKey, $data, MCRYPT_MODE_CBC, $iv);
- echo( $encrypted);
- echo '
';
- echo(base64_encode($encrypted));
- echo '
';
-
- //Decrypt
- $encryptedData = base64_decode("2fbwW9+ 8vPId2/foafZq6Q==");
- $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, $encryptedData, MCRYPT_MODE_CBC, $iv);
- echo($decrypted);
- ?>
Copy code
|