RSA is an asymmetric encryption algorithm that uses a public key to encrypt messages, and a private key to decrypt them. It is based on the difficulty of factoring large prime numbers. To generate a key pair, two large prime numbers are randomly selected and multiplied together. The public key contains the result of this multiplication and an encryption exponent, while the private key contains a decryption exponent. A message encrypted with the public key can only be decrypted with the private key.