To encrypt your files in vim, type :X
When vim prompts for an encryption key, key in your password which should be mandatory to open the file. Type the password again to confirm when the confirmation prompt comes in.
While opening the file again, vim prompts the password. If the incorrect password is entered, vim displays junk.