java.lang.Object
nl.andrewl.concord_core.msg.Encryption
Utility class for handling the establishment of encrypted communication.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]
computeSecretKey
(byte[] sharedSecret, byte[] pk1, byte[] pk2) static Pair<CipherInputStream,
CipherOutputStream> upgrade
(InputStream in, OutputStream out, Serializer serializer) Upgrades the given input and output streams to a pair of cipher input and output streams.
-
Constructor Details
-
Encryption
public Encryption()
-
-
Method Details
-
upgrade
public static Pair<CipherInputStream,CipherOutputStream> upgrade(InputStream in, OutputStream out, Serializer serializer) throws GeneralSecurityException, IOException Upgrades the given input and output streams to a pair of cipher input and output streams. This upgrade follows the following steps:- Generate an elliptic curve key pair, and send the public key to the output stream.
- Read the public key that the other person has sent, from the input stream.
- Compute a shared private key using the ECDH key exchange, with our private key and their public key.
- Create the cipher streams from the shared private key.
- Parameters:
in
- The unencrypted input stream.out
- The unencrypted output stream.serializer
- The message serializer that is used to read and write messages according to the standard Concord protocol.- Returns:
- The pair of cipher streams, which can be used to send encrypted messages.
- Throws:
GeneralSecurityException
- If an error occurs while generating keys or preparing the cipher streams.IOException
- If an error occurs while reading or writing data on the streams.
-
computeSecretKey
private static byte[] computeSecretKey(byte[] sharedSecret, byte[] pk1, byte[] pk2) throws NoSuchAlgorithmException - Throws:
NoSuchAlgorithmException
-