1 package civitas.crypto.sharedkey;
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.sharedkeyciphertext.SharedKeyCiphertext;
11 import civitas.crypto.sharedkeymsg.SharedKeyMsg;
12
13 @Controller
14 public class DecryptShared implements Constants {
15 @Autowired
16 CryptoBase cryptoBase;
17
18 public SharedKeyMsg apply(final SharedKey key, final SharedKeyCiphertext ciphertext) {
19 byte[] plaintext = cryptoBase.doCrypto(
20 SHARED_KEY_CIPHER_ALG, SHARED_KEY_PROVIDER, key.k(), Cipher.DECRYPT_MODE, ciphertext.encryptedBytes);
21 return new SharedKeyMsg(new String(plaintext, CHARSET));
22 }
23 }