@@ -178,8 +178,9 @@ public static KeyPair readRSAPrivateKey(final byte[] input)
178
178
179
179
public static KeyPair readRSAPrivateKey (final KeyFactory rsaFactory , final byte [] input )
180
180
throws IOException , InvalidKeySpecException {
181
- ASN1Sequence seq = (ASN1Sequence ) new ASN1InputStream (input ).readObject ();
182
- if ( seq .size () == 9 ) {
181
+ ASN1Sequence seq ;
182
+ ASN1Primitive obj = new ASN1InputStream (input ).readObject ();
183
+ if (obj instanceof ASN1Sequence && (seq = (ASN1Sequence ) obj ).size () == 9 ) {
183
184
BigInteger mod = ((ASN1Integer ) seq .getObjectAt (1 )).getValue ();
184
185
BigInteger pubexp = ((ASN1Integer ) seq .getObjectAt (2 )).getValue ();
185
186
BigInteger privexp = ((ASN1Integer ) seq .getObjectAt (3 )).getValue ();
@@ -203,8 +204,9 @@ public static PublicKey readRSAPublicKey(final byte[] input)
203
204
204
205
public static PublicKey readRSAPublicKey (final KeyFactory rsaFactory , final byte [] input )
205
206
throws IOException , InvalidKeySpecException {
206
- ASN1Sequence seq = (ASN1Sequence ) new ASN1InputStream (input ).readObject ();
207
- if ( seq .size () == 2 ) {
207
+ ASN1Sequence seq ;
208
+ ASN1Primitive obj = new ASN1InputStream (input ).readObject ();
209
+ if (obj instanceof ASN1Sequence && (seq = (ASN1Sequence ) obj ).size () == 2 ) {
208
210
BigInteger mod = ((ASN1Integer ) seq .getObjectAt (0 )).getValue ();
209
211
BigInteger pubexp = ((ASN1Integer ) seq .getObjectAt (1 )).getValue ();
210
212
return rsaFactory .generatePublic (new RSAPublicKeySpec (mod , pubexp ));
@@ -220,8 +222,9 @@ public static KeyPair readDSAPrivateKey(final byte[] input)
220
222
221
223
public static KeyPair readDSAPrivateKey (final KeyFactory dsaFactory , final byte [] input )
222
224
throws IOException , InvalidKeySpecException {
223
- ASN1Sequence seq = (ASN1Sequence ) new ASN1InputStream (input ).readObject ();
224
- if ( seq .size () == 6 ) {
225
+ ASN1Sequence seq ;
226
+ ASN1Primitive obj = new ASN1InputStream (input ).readObject ();
227
+ if (obj instanceof ASN1Sequence && (seq = (ASN1Sequence ) obj ).size () == 6 ) {
225
228
BigInteger p = ((ASN1Integer ) seq .getObjectAt (1 )).getValue ();
226
229
BigInteger q = ((ASN1Integer ) seq .getObjectAt (2 )).getValue ();
227
230
BigInteger g = ((ASN1Integer ) seq .getObjectAt (3 )).getValue ();
0 commit comments