package de.uni.trier.infsec.functionalities.symenc.real;

import static de.uni.trier.infsec.utils.MessageTools.copyOf;
import de.uni.trier.infsec.lib.crypto.CryptoLib;

/**
 * Real functionality for private symmetric key encrytpion.
 * 
 * This functionality is meant to be used, if a user wants to generate
 * a symmetric key to be used solely by her. The functionality provides
 * no means to share the key. The key is generated in the constructor
 * and never leaves the object.
 */
public class SymEnc {
	private byte[] key;
	
	public SymEnc() {
		key = CryptoLib.symkey_generateKey();
	}
	
	public byte[] encrypt(byte[] plaintext) {
		return CryptoLib.symkey_encrypt(copyOf(key), copyOf(plaintext));
	}
	
	public byte[] decrypt(byte[] ciphertext) {
		return CryptoLib.symkey_decrypt(copyOf(key), copyOf(ciphertext));
	}
}

@@ -818,10 +818,207 @@
 t));%0A%09%7D%0A
+%09%0A%09/// Extended interface (not in the ideal functionality): serialization/deserialization of SymEnc ///%0A%09%0A%09public SymEnc(byte%5B%5D key)%7B%0A%09%09this.key=key;%0A%09%7D%0A%09%0A%09public byte%5B%5D getKey()%7B%0A%09%09return key;%0A%09%7D%0A
 %7D%0A

extend real SymEnc by serialization methods