Module concord_core

Class Encryption

java.lang.Object
nl.andrewl.concord_core.msg.Encryption

public class Encryption extends Object
Utility class for handling the establishment of encrypted communication.
  • Constructor Details

    • Encryption

      public Encryption()
  • Method Details

    • upgrade

      Upgrades the given input and output streams to a pair of cipher input and output streams. This upgrade follows the following steps:
      1. Generate an elliptic curve key pair, and send the public key to the output stream.
      2. Read the public key that the other person has sent, from the input stream.
      3. Compute a shared private key using the ECDH key exchange, with our private key and their public key.
      4. 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