Ejemplo n.º 1
0
 /**
  * Returns a new instance of {@code MessageDigest} that utilizes the specified algorithm.
  *
  * @param algorithm the name of the algorithm to use
  * @return a new instance of {@code MessageDigest} that utilizes the specified algorithm
  * @throws NoSuchAlgorithmException if the specified algorithm is not available
  * @throws NullPointerException if {@code algorithm} is {@code null}
  */
 public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException {
   if (algorithm == null) {
     throw new NullPointerException();
   }
   MessageDigest result;
   synchronized (engine) {
     engine.getInstance(algorithm, null);
     if (engine.spi instanceof MessageDigest) {
       result = (MessageDigest) engine.spi;
       result.algorithm = algorithm;
       result.provider = engine.provider;
       return result;
     }
     return new MessageDigestImpl((MessageDigestSpi) engine.spi, engine.provider, algorithm);
   }
 }