1 /* |
1 /* |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
36 import java.security.Key; |
36 import java.security.Key; |
37 import java.security.PublicKey; |
37 import java.security.PublicKey; |
38 import java.security.PrivateKey; |
38 import java.security.PrivateKey; |
39 import java.security.KeyFactorySpi; |
39 import java.security.KeyFactorySpi; |
40 |
40 |
41 import java.security.spec.InvalidKeySpecException; |
41 import java.security.spec.*; |
42 import java.security.spec.KeySpec; |
|
43 import java.security.spec.RSAPrivateCrtKeySpec; |
|
44 import java.security.spec.RSAPublicKeySpec; |
|
45 |
42 |
46 /** |
43 /** |
47 * Ucrypto-private KeyFactory class for generating native keys |
44 * Ucrypto-private KeyFactory class for generating native keys |
48 * needed for using ucrypto APIs. Given that it's not used |
45 * needed for using ucrypto APIs. |
49 * externally, it only needs to support RSAPrivateCrtKeySpec |
|
50 * and RSAPublicKeySpec objects. |
|
51 * |
46 * |
52 * @since 1.9 |
47 * @since 1.9 |
53 */ |
48 */ |
54 public final class NativeRSAKeyFactory extends KeyFactorySpi { |
49 public final class NativeRSAKeyFactory extends KeyFactorySpi { |
55 |
50 |
56 @Override |
51 @Override |
57 protected PrivateKey engineGeneratePrivate(KeySpec keySpec) |
52 protected PrivateKey engineGeneratePrivate(KeySpec keySpec) |
58 throws InvalidKeySpecException { |
53 throws InvalidKeySpecException { |
59 return new NativeKey.RSAPrivateCrt(keySpec); |
54 if (keySpec instanceof RSAPrivateCrtKeySpec) { |
|
55 return new NativeKey.RSAPrivateCrt(keySpec); |
|
56 } else if (keySpec instanceof RSAPrivateKeySpec) { |
|
57 return new NativeKey.RSAPrivate(keySpec); |
|
58 } else { |
|
59 throw new InvalidKeySpecException("Unsupported key spec"); |
|
60 } |
60 } |
61 } |
61 |
62 |
62 @Override |
63 @Override |
63 protected PublicKey engineGeneratePublic(KeySpec keySpec) |
64 protected PublicKey engineGeneratePublic(KeySpec keySpec) |
64 throws InvalidKeySpecException { |
65 throws InvalidKeySpecException { |