1 package civitas.crypto.sharedkeyciphertext;
2
3 import javax.crypto.Cipher;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller;
7
8 import civitas.crypto.Constants;
9 import civitas.crypto.CryptoBase;
10 import civitas.crypto.sharedkey.SharedKey;
11 import civitas.crypto.sharedkeymsg.SharedKeyMsg;
12
13 @Controller
14 public class EncryptShared implements Constants {
15 @Autowired
16 CryptoBase cryptoBase;
17
18 public SharedKeyCiphertext apply(final SharedKey key, final SharedKeyMsg msg) {
19 SharedKey keyc = key;
20 SharedKeyMsg msgc = msg;
21 byte[] encrypted = cryptoBase.doCrypto(
22 SHARED_KEY_CIPHER_ALG,
23 SHARED_KEY_PROVIDER,
24 keyc.k(),
25 Cipher.ENCRYPT_MODE,
26 msgc.m().getBytes());
27 return new SharedKeyCiphertext(encrypted);
28 }
29 }