Skip to content

Encryption

Thorben Kuck edited this page Sep 19, 2018 · 3 revisions

Encryption

Details

You can Encrypt your communication or more specific the objects that are beeing send over the Connection. This is done by providing an implementation of the EncryptionAdapter/DecryptionAdapter to an Client, which is another form of the Adapter<String, String> interface. Both take an Serialized String and encrypt/decrypt it. The new String is than returned.
Important is, that both, the Encryption and DecryptionAdapter are provided.

The most Common way to add those two is, to add them inside of an ClientConnectedHandler:

ServerStart serverStart = ...
EncryptionAdapter encrypt = ...
DecryptionAdapter decrypt = ...

serverStart.addClientConnectedHandler(client -> {
    ObjectHandler handler = client.objectHandler();
    objectHandler.addEncryptionAdapter(encrypt);
    objectHandler.addDecryptionAdapter(decrypt);
});

Applications

If you want to add an simple caesar cipher and you have the methods ciper(String, int) and deciper(String, int), which take the string and return the provided String shiftet by an amount, provided via the int. You could ciper your Communication by stating the following:

ServerStart serverStart = ...

serverStart.addClientConnectedHandler(client -> {
    client.objectHandler().addEncryptionAdapter(string -> cypher(string, 3));
    client.objectHandler().addDecryptionAdapter(string -> decypher(string, 3));
});

Of course you can add some more complicated En/Decryptions, like RSA or something.