While symmetric cryptography is faster, asymmetric cryptography is often more practical and secure. In practice, both types of cryptosystems are often used together. For instance, a user might choose to encrypt a long message by using a symmetric system and then use an asymmetrical system to share the private key. While the asymmetrical system will be slower, the symmetrical key will likely be shorter and faster to decrypt than the full message.
However, both types of systems can be vulnerable to so-called man-in-the-middle (MitM) attacks, in which a malicious eavesdropper might intercept secure data during transmission.
In such an attack, a hacker or bad actor might intercept a public key, create their own private key and then replace the authentic public key with one that has been compromised. The hacker might then intercept encrypted messages sent between parties over the compromised asymmetric system, decrypt the message, read the contents, encrypt them again and forward along the now-compromised message. For the users, the effect would be the same, and the effective attack would be undetectable.
To prevent these types of attacks, public key infrastructure (PKI) uses digital certificates (also known as PKI certificates, public key certificates and X.509 certificates) to confirm the identity of people, devices and/or applications that own the private and corresponding public keys. PKI provides the framework to effectively assign authenticated ownership of cryptographic keys—ensuring that when information is sent over an asymmetric cryptosystem, only the verified and intended recipient will be able to decrypt it.