Today at the University we learned if Alice gives Bob her private key and vice versa, they can identify them self. It make sense but is this good practice? I always thought that Certificates are made for this scenerio?
if Alice gives Bob her private key and vice versa, they can identify them self
I think you've misunderstood something. For identification Alice does not give Bob her private key to identity herself.
Instead Bob issues a challenge (i.e. some random message) and Alice signs this challenge with the her private key. Bob then can verify this signature using Alice public key (which is public as the name says, i.e. known to Bob). And since Bob had control of the challenge he can be sure that Alice is currently in possession of the matching private key. Since only Alice should know this secret private key this can be used as a proof that this is Alice at the other end of the connection, i.e. proof of Alice identity.
In the real world you have a double wrapped message.
- Alice encrypts the plaintext with Bob's public key so only Bob can read it.
- Then Alice encrypts the cryptotext with her private key to generate cryptotext2.
- Bob then uses Alice's public key to decrypt the cryptotext2.
- Bob then uses his private key to decrypt cryptotext into plaintext.
It is Step 2 and 3 that validate that Alice is the one who sent the message.