public class Connection extends Object
| Modifier and Type | Field and Description |
|---|---|
DataInputStream |
din |
DataOutputStream |
dout |
InputStream |
in |
OutputStream |
out |
| Constructor and Description |
|---|
Connection(InputStream in,
OutputStream out) |
Connection(Socket socket) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
KeyAgreement |
diffieHellman(boolean side)
Performs a Diffie-Hellman key exchange and produce a common secret between two ends of the connection.
|
KeyAgreement |
diffieHellman(boolean side,
int keySize) |
Connection |
encryptConnection(SecretKey sessionKey,
String algorithm)
Upgrades a connection with transport encryption by the specified symmetric cipher.
|
static byte[] |
fold(byte[] bytes,
int size)
Given a byte array that contains arbitrary number of bytes, digests or expands those bits into the specified
number of bytes without loss of entropy.
|
void |
proveIdentity(byte[] sharedSecret,
KeyPair key)
Used in conjunction with
verifyIdentity(byte[]) to prove
that we actually own the private key of the given key pair. |
boolean |
readBoolean() |
byte[] |
readByteArray() |
X509EncodedKeySpec |
readKey() |
<T> T |
readObject()
Receives an object sent by
writeObject(Object) |
String |
readUTF() |
PublicKey |
verifyIdentity(byte[] sharedSecret)
Verifies that we are talking to a peer that actually owns the private key corresponding to the public key we get.
|
void |
writeBoolean(boolean b) |
void |
writeByteArray(byte[] data) |
void |
writeKey(Key key) |
void |
writeObject(Object o)
Sends a serializable object.
|
void |
writeUTF(String msg) |
public final InputStream in
public final OutputStream out
public final DataInputStream din
public final DataOutputStream dout
public Connection(Socket socket) throws IOException
IOExceptionpublic Connection(InputStream in, OutputStream out)
public void writeUTF(String msg) throws IOException
IOExceptionpublic String readUTF() throws IOException
IOExceptionpublic void writeBoolean(boolean b)
throws IOException
IOExceptionpublic boolean readBoolean()
throws IOException
IOExceptionpublic void writeObject(Object o) throws IOException
IOExceptionpublic <T> T readObject()
throws IOException,
ClassNotFoundException
writeObject(Object)IOExceptionClassNotFoundExceptionpublic void writeKey(Key key) throws IOException
IOExceptionpublic X509EncodedKeySpec readKey() throws IOException
IOExceptionpublic void writeByteArray(byte[] data)
throws IOException
IOExceptionpublic byte[] readByteArray()
throws IOException
IOExceptionpublic KeyAgreement diffieHellman(boolean side) throws IOException, GeneralSecurityException
DH is also useful as a coin-toss algorithm. Two parties get the same random number without trusting each other.
IOExceptionGeneralSecurityExceptionpublic KeyAgreement diffieHellman(boolean side, int keySize) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic Connection encryptConnection(SecretKey sessionKey, String algorithm) throws IOException, GeneralSecurityException
Connection object that includes the transport encryption.IOExceptionGeneralSecurityExceptionpublic static byte[] fold(byte[] bytes,
int size)
public void proveIdentity(byte[] sharedSecret,
KeyPair key)
throws IOException,
GeneralSecurityException
verifyIdentity(byte[]) to prove
that we actually own the private key of the given key pair.IOExceptionGeneralSecurityExceptionpublic PublicKey verifyIdentity(byte[] sharedSecret) throws IOException, GeneralSecurityException
IOExceptionGeneralSecurityExceptionpublic void close()
throws IOException
IOExceptionCopyright © 2004-2015. All Rights Reserved.