Replaced Windows API with existing code to handle PEM files