< prev index next >

src/java.base/share/classes/java/security/MessageDigest.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 220      *         specified algorithm
 221      *
 222      * @throws IllegalArgumentException if the provider name is {@code null}
 223      *         or empty
 224      *
 225      * @throws NoSuchAlgorithmException if a {@code MessageDigestSpi}
 226      *         implementation for the specified algorithm is not
 227      *         available from the specified provider
 228      *
 229      * @throws NoSuchProviderException if the specified provider is not
 230      *         registered in the security provider list
 231      *
 232      * @throws NullPointerException if {@code algorithm} is {@code null}
 233      *
 234      * @see Provider
 235      */
 236     public static MessageDigest getInstance(String algorithm, String provider)
 237         throws NoSuchAlgorithmException, NoSuchProviderException
 238     {
 239         Objects.requireNonNull(algorithm, "null algorithm name");
 240         if (provider == null || provider.length() == 0)
 241             throw new IllegalArgumentException("missing provider");
 242         Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
 243         if (objs[0] instanceof MessageDigest) {
 244             MessageDigest md = (MessageDigest)objs[0];
 245             md.provider = (Provider)objs[1];
 246             return md;
 247         } else {
 248             MessageDigest delegate =
 249                 new Delegate((MessageDigestSpi)objs[0], algorithm);
 250             delegate.provider = (Provider)objs[1];
 251             return delegate;
 252         }
 253     }
 254 
 255     /**
 256      * Returns a MessageDigest object that implements the specified digest
 257      * algorithm.
 258      *
 259      * <p> A new MessageDigest object encapsulating the
 260      * MessageDigestSpi implementation from the specified Provider




 220      *         specified algorithm
 221      *
 222      * @throws IllegalArgumentException if the provider name is {@code null}
 223      *         or empty
 224      *
 225      * @throws NoSuchAlgorithmException if a {@code MessageDigestSpi}
 226      *         implementation for the specified algorithm is not
 227      *         available from the specified provider
 228      *
 229      * @throws NoSuchProviderException if the specified provider is not
 230      *         registered in the security provider list
 231      *
 232      * @throws NullPointerException if {@code algorithm} is {@code null}
 233      *
 234      * @see Provider
 235      */
 236     public static MessageDigest getInstance(String algorithm, String provider)
 237         throws NoSuchAlgorithmException, NoSuchProviderException
 238     {
 239         Objects.requireNonNull(algorithm, "null algorithm name");
 240         if (provider == null || provider.isEmpty())
 241             throw new IllegalArgumentException("missing provider");
 242         Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
 243         if (objs[0] instanceof MessageDigest) {
 244             MessageDigest md = (MessageDigest)objs[0];
 245             md.provider = (Provider)objs[1];
 246             return md;
 247         } else {
 248             MessageDigest delegate =
 249                 new Delegate((MessageDigestSpi)objs[0], algorithm);
 250             delegate.provider = (Provider)objs[1];
 251             return delegate;
 252         }
 253     }
 254 
 255     /**
 256      * Returns a MessageDigest object that implements the specified digest
 257      * algorithm.
 258      *
 259      * <p> A new MessageDigest object encapsulating the
 260      * MessageDigestSpi implementation from the specified Provider


< prev index next >