A cryptographic technique called X25519 is used in private messages to safely transfer keys between devices, ensuring that only the intended recipients can read the messages.