equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2018, 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 |
29 |
29 |
30 import java.security.*; |
30 import java.security.*; |
31 import java.security.interfaces.*; |
31 import java.security.interfaces.*; |
32 import java.security.spec.*; |
32 import java.security.spec.*; |
33 |
33 |
|
34 import sun.security.rsa.RSAPublicKeyImpl; |
34 import static sun.security.pkcs11.TemplateManager.*; |
35 import static sun.security.pkcs11.TemplateManager.*; |
35 import sun.security.pkcs11.wrapper.*; |
36 import sun.security.pkcs11.wrapper.*; |
36 import static sun.security.pkcs11.wrapper.PKCS11Constants.*; |
37 import static sun.security.pkcs11.wrapper.PKCS11Constants.*; |
37 |
38 |
38 import sun.security.rsa.RSAKeyFactory; |
39 import sun.security.rsa.RSAKeyFactory; |
58 rsaKey.getPublicExponent() |
59 rsaKey.getPublicExponent() |
59 ); |
60 ); |
60 } else if ("X.509".equals(key.getFormat())) { |
61 } else if ("X.509".equals(key.getFormat())) { |
61 // let SunRsaSign provider parse for us, then recurse |
62 // let SunRsaSign provider parse for us, then recurse |
62 byte[] encoded = key.getEncoded(); |
63 byte[] encoded = key.getEncoded(); |
63 key = new sun.security.rsa.RSAPublicKeyImpl(encoded); |
64 key = RSAPublicKeyImpl.newKey(encoded); |
64 return implTranslatePublicKey(key); |
65 return implTranslatePublicKey(key); |
65 } else { |
66 } else { |
66 throw new InvalidKeyException("PublicKey must be instance " |
67 throw new InvalidKeyException("PublicKey must be instance " |
67 + "of RSAPublicKey or have X.509 encoding"); |
68 + "of RSAPublicKey or have X.509 encoding"); |
68 } |
69 } |
111 throws InvalidKeySpecException { |
112 throws InvalidKeySpecException { |
112 token.ensureValid(); |
113 token.ensureValid(); |
113 if (keySpec instanceof X509EncodedKeySpec) { |
114 if (keySpec instanceof X509EncodedKeySpec) { |
114 try { |
115 try { |
115 byte[] encoded = ((X509EncodedKeySpec)keySpec).getEncoded(); |
116 byte[] encoded = ((X509EncodedKeySpec)keySpec).getEncoded(); |
116 PublicKey key = new sun.security.rsa.RSAPublicKeyImpl(encoded); |
117 PublicKey key = RSAPublicKeyImpl.newKey(encoded); |
117 return implTranslatePublicKey(key); |
118 return implTranslatePublicKey(key); |
118 } catch (InvalidKeyException e) { |
119 } catch (InvalidKeyException e) { |
119 throw new InvalidKeySpecException |
120 throw new InvalidKeySpecException |
120 ("Could not create RSA public key", e); |
121 ("Could not create RSA public key", e); |
121 } |
122 } |