1 package civitas.crypto.rsaprivatekey;
2
3 import java.security.spec.InvalidKeySpecException;
4 import java.security.spec.KeySpec;
5 import java.security.spec.PKCS8EncodedKeySpec;
6
7 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Controller;
9
10 import civitas.crypto.CryptoBase;
11 import civitas.crypto.CryptoError;
12
13 @Controller
14 public class CreatePrivateKeyFromBytes {
15
16 @Autowired
17 CryptoBase cryptoBase;
18
19 public java.security.PrivateKey apply(final byte[] bs) {
20 KeySpec keySpec = new PKCS8EncodedKeySpec(bs);
21 try {
22 return cryptoBase.publicKeyFactory.generatePrivate(keySpec);
23 } catch (InvalidKeySpecException e) {
24 throw new CryptoError(e);
25 }
26 }
27 }