'How to encrypt values sended via sockets

I have this client/server programs where the client must send his password to the server. Is there any way to encrypt these data sended by the client? I have them saved as a string and at the moment I'm using this to send and receive them:

Client's socket

Socket socket = new Socket(ServerIP, 8000);

private void sendMessage(String userEmail, String userPassword){
 //create a data output stream from the output stream to send data
 OutputStream outputStream = socket.getOutputStream();
 DataOutputStream dataOutputStream = new DataOutputStream(outputStream);

 //write, send the message and close the stream
 dataOutputStream.writeUTF(userPassword);
 dataOutputStream.flush();
 dataOutputStream.close();
 socket.close();
}

Server's socket

ServerSocket serSocket = new ServerSocket(8000);

private void receiveData(){
 Socket socket = serSocket.accept();   //wait for connection

 InputStream inputStream = socket.getInputStream();   //get the input from another socket
 DataInputStream dataInputStream = new DataInputStream(inputStream);

 String userData = dataInputStream.readUTF();
 //save userData in a database
 socket.close();
}
serSocket.close();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source