2323import java .io .FileInputStream ;
2424import java .io .IOException ;
2525import java .io .InputStream ;
26- import java .io .InputStreamReader ;
2726import java .io .OutputStream ;
2827import java .math .BigInteger ;
2928import java .security .GeneralSecurityException ;
4443import java .util .Map ;
4544import java .util .logging .Level ;
4645import java .util .logging .Logger ;
47- import org .bouncycastle .openssl .PEMReader ;
4846
4947/**
5048 * Key store loader. This class loads a key store from
@@ -82,14 +80,11 @@ public final X509Certificate getCertificate(String alias) throws KeyStoreExcepti
8280 * @throws GeneralSecurityException
8381 */
8482 public final PrivateKey getPrivateKey (String alias ) throws GeneralSecurityException {
85- PrivateKey key ;
86-
87- key = (PrivateKey ) keyStore .getKey (alias , password );
88- if (key == null ) {
89- throw new IllegalArgumentException ("private key not found for alias " + alias );
90- }
91-
92- return key ;
83+ PrivateKey key = (PrivateKey ) keyStore .getKey (alias , password );
84+ if (key == null ) {
85+ throw new IllegalArgumentException ("private key not found for alias " + alias );
86+ }
87+ return key ;
9388 }
9489
9590 /**
@@ -128,36 +123,23 @@ private void load(File path) throws GeneralSecurityException, IOException {
128123 * @param provider the certificate provider
129124 * @return the certificate
130125 * @throws CertificateException
131- * @throws IOException
132126 */
133127 public X509Certificate read (InputStream input , Provider provider )
134- throws CertificateException , IOException
135- {
136- X509Certificate certificate ;
137-
138- certificate = (X509Certificate ) CertificateFactory .getInstance ("X.509" , provider ).generateCertificate (input );
139-
140- if (certificate == null ) {
141- certificate = (X509Certificate )(new PEMReader (new InputStreamReader (input ))).readObject ();
142- }
143-
144- return certificate ;
128+ throws CertificateException {
129+ return (X509Certificate ) CertificateFactory .getInstance ("X.509" ,
130+ provider ).generateCertificate (input );
145131 }
146132
147133 /**
148134 * Returns the public key of a given certificate.
149135 * @param input the given certificate
150136 * @return The RSA public key of the given certificate
151137 * @throws GeneralSecurityException
152- * @throws IOException
153138 */
154- public RSAPublicKey getPublicKey (InputStream input )
155- throws GeneralSecurityException , IOException
156- {
157- X509Certificate cert ;
139+ public RSAPublicKey getPublicKey (InputStream input ) throws GeneralSecurityException {
158140
159- cert = read (input , keyStore .getProvider ());
160- return (RSAPublicKey ) cert .getPublicKey ();
141+ X509Certificate cert = read (input , keyStore .getProvider ());
142+ return (RSAPublicKey ) cert .getPublicKey ();
161143 }
162144
163145 public RSAPublicKey getPublicKey (BigInteger publicExponent , BigInteger modulus )
@@ -169,7 +151,7 @@ public RSAPublicKey getPublicKey(BigInteger publicExponent, BigInteger modulus)
169151 return null ;
170152 }
171153 }
172-
154+
173155 /**
174156 * Writes the given certificate into the key store.
175157 * @param alias the certificate alias
@@ -192,7 +174,7 @@ public void save(OutputStream output)
192174 {
193175 keyStore .store (output , password );
194176 }
195-
177+
196178 /**
197179 * Returns the certificates contained in the key store.
198180 * @return the certificates contained in the key store.
@@ -208,29 +190,21 @@ public Map<String, X509Certificate> getCertificates() {
208190 * the key of the map is the certificate alias
209191 * @throws KeyStoreException
210192 */
211- public Map <String , X509Certificate > read (KeyStore keyStore )
212- throws KeyStoreException
213- {
214- Map <String , X509Certificate > certificates ;
215- Enumeration <String > enumeration ;
216-
217- certificates = new HashMap <String , X509Certificate >();
218- enumeration = keyStore .aliases ();
219- while (enumeration .hasMoreElements ()) {
220- String alias ;
221-
222- alias = enumeration .nextElement ();
223- certificates .put (alias , (X509Certificate )keyStore .getCertificate (alias ));
224- }
225-
226- return certificates ;
193+ public Map <String , X509Certificate > read (KeyStore keyStore ) throws KeyStoreException {
194+ Map <String , X509Certificate > certificates = new HashMap <>();
195+ Enumeration <String > enumeration = keyStore .aliases ();
196+ while (enumeration .hasMoreElements ()) {
197+ String alias = enumeration .nextElement ();
198+ certificates .put (alias , (X509Certificate ) keyStore .getCertificate (alias ));
199+ }
200+ return certificates ;
227201 }
228202
229203 // --------------------------------------------------------------------
230204 // DATA MEMBERS
231205 // --------------------------------------------------------------------
232206
233- private KeyStore keyStore ;
234- private char [] password ;
235- private Map <String , X509Certificate > certs ;
207+ private KeyStore keyStore ;
208+ private char [] password ;
209+ private Map <String , X509Certificate > certs ;
236210}
0 commit comments