Seems like $_POST['msg'] might need to be base64_decode()'d as well? Also, try doing $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1)
. By default phpseclib does OAEP padding which, although more secure, is not as widely supported nor is it the default for most stuff.