Yes, this is absolutely okay and appears countless times in the repertoire. This particular voice-exchange progression is very common, and the way you've written it is the smoothest voice leading. That diminished fifth moving to perfect fifth is absolutely fine.