Example #1
0
        /**
         * Returns a new instance of {@code MessageDigest} that utilizes the
         * specified algorithm from the specified provider.
         *
         * @param algorithm
         *            the name of the algorithm to use
         * @param provider
         *            the provider
         * @return a new instance of {@code MessageDigest} that utilizes the
         *         specified algorithm from the specified provider
         * @throws NoSuchAlgorithmException
         *             if the specified algorithm is not available
         * @throws NullPointerException
         *             if {@code algorithm} is {@code null}
         */
        public static MessageDigest getInstance(String algorithm, Provider provider)
        {//throws NoSuchAlgorithmException {
            if (provider == null)
            {
                throw new java.lang.IllegalArgumentException("Provider is null"); //$NON-NLS-1$
            }
            if (algorithm == null)
            {
                throw new java.lang.NullPointerException("Algorithm is null"); //$NON-NLS-1$
            }
            MessageDigest result;

            lock (engine)
            {
                engine.getInstance(algorithm, provider, null);
                if (engine.spi is MessageDigest)
                {
                    result           = (MessageDigest)engine.spi;
                    result.algorithm = algorithm;
                    result.provider  = provider;
                    return(result);
                }
                result = new MessageDigestImpl((MessageDigestSpi)engine.spi,
                                               provider, algorithm);
                return(result);
            }
        }
Example #2
0
 /**
  * Returns a new instance of {@code MessageDigest} that utilizes the
  * specified algorithm from the specified provider.
  *
  * @param algorithm
  *            the name of the algorithm to use
  * @param provider
  *            the provider
  * @return a new instance of {@code MessageDigest} that utilizes the
  *         specified algorithm from the specified provider
  * @throws NoSuchAlgorithmException
  *             if the specified algorithm is not available
  * @throws NullPointerException
  *             if {@code algorithm} is {@code null}
  */
 public static MessageDigest getInstance(String algorithm, Provider provider)
 {
     //throws NoSuchAlgorithmException {
     if (provider == null)
     {
         throw new java.lang.IllegalArgumentException("Provider is null"); //$NON-NLS-1$
     }
     if (algorithm == null)
     {
         throw new java.lang.NullPointerException("Algorithm is null"); //$NON-NLS-1$
     }
     MessageDigest result;
     lock (engine)
     {
         engine.getInstance(algorithm, provider, null);
         if (engine.spi is MessageDigest)
         {
             result = (MessageDigest)engine.spi;
             result.algorithm = algorithm;
             result.provider = provider;
             return result;
         }
         result = new MessageDigestImpl((MessageDigestSpi)engine.spi,
                 provider, algorithm);
         return result;
     }
 }