public static function decrypt($encryptionKey, $encryptedString, $blockType = 'CBC', $urlSafe = false) { if ($urlSafe) { $data = Base64URLSafe::urlsafe_b64decode($encryptedString); } else { $data = base64_decode($encryptedString); } switch ($blockType) { case 'CBC': $cipher = new Rijndael(Rijndael::MODE_CBC); $cipher->setKey($encryptionKey); // Split the IV from the ciphertext $iv = substr($data, 0, $cipher->getBlockLength() >> 3); $cipherText = substr($data, $cipher->getBlockLength() >> 3, strlen($encryptedString)); $cipher->setIV($iv); break; case 'ECB': $cipher = new Rijndael(Rijndael::MODE_ECB); $cipher->setKey($encryptionKey); $cipherText = $data; break; default: throw new \Exception('Unknown encryption blocktype: ' . $blockType, 500); break; } return $cipher->decrypt($cipherText); }