If we withheld tax for a foreign entity and paid the withholding tax in RMB to tax authority, and then the foreign entity repaid us an equivalent amount of foreign exchange, is it allowed by SAFE?

No. It’s illegal.