1 package civitas.crypto.sharedkey;
2
3 import java.security.spec.InvalidKeySpecException;
4
5 import javax.crypto.SecretKey;
6 import javax.crypto.spec.SecretKeySpec;
7
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Controller;
10
11 import civitas.crypto.Constants;
12 import civitas.crypto.CryptoBase;
13 import civitas.crypto.CryptoError;
14
15 @Controller
16 public class CreateSharedKeyFromBytes implements Constants {
17
18 @Autowired
19 CryptoBase cryptoBase;
20
21 public SecretKey apply(final byte[] bs) {
22 SecretKeySpec skeySpec = new SecretKeySpec(bs, SHARED_KEY_ALG);
23 try {
24 return cryptoBase.sharedKeyFactory.generateSecret(skeySpec);
25 } catch (InvalidKeySpecException e) {
26 throw new CryptoError(e);
27 }
28 }
29 }