1
1
/*
2
- * Copyright (c) 2018, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -170,8 +170,7 @@ public static AlgorithmParameterSpec getParamSpec(String sigName,
170
170
// for verification with the specified key and params (may be null)
171
171
public static void initVerifyWithParam (Signature s , PublicKey key ,
172
172
AlgorithmParameterSpec params )
173
- throws ProviderException , InvalidAlgorithmParameterException ,
174
- InvalidKeyException {
173
+ throws InvalidAlgorithmParameterException , InvalidKeyException {
175
174
SharedSecrets .getJavaSecuritySignatureAccess ().initVerify (s , key , params );
176
175
}
177
176
@@ -180,17 +179,15 @@ public static void initVerifyWithParam(Signature s, PublicKey key,
180
179
public static void initVerifyWithParam (Signature s ,
181
180
java .security .cert .Certificate cert ,
182
181
AlgorithmParameterSpec params )
183
- throws ProviderException , InvalidAlgorithmParameterException ,
184
- InvalidKeyException {
182
+ throws InvalidAlgorithmParameterException , InvalidKeyException {
185
183
SharedSecrets .getJavaSecuritySignatureAccess ().initVerify (s , cert , params );
186
184
}
187
185
188
186
// Utility method for initializing the specified Signature object
189
187
// for signing with the specified key and params (may be null)
190
188
public static void initSignWithParam (Signature s , PrivateKey key ,
191
189
AlgorithmParameterSpec params , SecureRandom sr )
192
- throws ProviderException , InvalidAlgorithmParameterException ,
193
- InvalidKeyException {
190
+ throws InvalidAlgorithmParameterException , InvalidKeyException {
194
191
SharedSecrets .getJavaSecuritySignatureAccess ().initSign (s , key , params , sr );
195
192
}
196
193
@@ -342,10 +339,10 @@ public static AlgorithmParameterSpec getDefaultParamSpec(
342
339
* Create a Signature that has been initialized with proper key and params.
343
340
*
344
341
* @param sigAlg signature algorithms
345
- * @param key public or private key
342
+ * @param key private key
346
343
* @param provider (optional) provider
347
344
*/
348
- public static Signature fromKey (String sigAlg , Key key , String provider )
345
+ public static Signature fromKey (String sigAlg , PrivateKey key , String provider )
349
346
throws NoSuchAlgorithmException , NoSuchProviderException ,
350
347
InvalidKeyException {
351
348
Signature sigEngine = (provider == null || provider .isEmpty ())
@@ -358,28 +355,23 @@ public static Signature fromKey(String sigAlg, Key key, String provider)
358
355
* Create a Signature that has been initialized with proper key and params.
359
356
*
360
357
* @param sigAlg signature algorithms
361
- * @param key public or private key
358
+ * @param key private key
362
359
* @param provider (optional) provider
363
360
*/
364
- public static Signature fromKey (String sigAlg , Key key , Provider provider )
361
+ public static Signature fromKey (String sigAlg , PrivateKey key , Provider provider )
365
362
throws NoSuchAlgorithmException , InvalidKeyException {
366
363
Signature sigEngine = (provider == null )
367
364
? Signature .getInstance (sigAlg )
368
365
: Signature .getInstance (sigAlg , provider );
369
366
return autoInitInternal (sigAlg , key , sigEngine );
370
367
}
371
368
372
- private static Signature autoInitInternal (String alg , Key key , Signature s )
369
+ private static Signature autoInitInternal (String alg , PrivateKey key , Signature s )
373
370
throws InvalidKeyException {
374
371
AlgorithmParameterSpec params = SignatureUtil
375
372
.getDefaultParamSpec (alg , key );
376
373
try {
377
- if (key instanceof PrivateKey ) {
378
- SignatureUtil .initSignWithParam (s , (PrivateKey ) key , params ,
379
- null );
380
- } else {
381
- SignatureUtil .initVerifyWithParam (s , (PublicKey ) key , params );
382
- }
374
+ SignatureUtil .initSignWithParam (s , key , params , null );
383
375
} catch (InvalidAlgorithmParameterException e ) {
384
376
throw new AssertionError ("Should not happen" , e );
385
377
}
0 commit comments