Prepare message digest message digest.

@param principal the principal
@param service   the service
@return the message digest
@throws NoSuchAlgorithmException the no such algorithm exception
182130
protected static MessageDigest prepareMessageDigest(final String principal, final String service) throws NoSuchAlgorithmException {
        val md = MessageDigest.getInstance("SHA");
        if (StringUtils.isNotBlank(service)) {
            md.update(service.getBytes(StandardCharsets.UTF_8));
            md.update(CONST_SEPARATOR);
        }
        md.update(principal.getBytes(StandardCharsets.UTF_8));
        md.update(CONST_SEPARATOR);
        return md;
    }
126656
public static byte[] computeHash(String passwd) throws NoSuchAlgorithmException  {
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
        md.reset();
        md.update(passwd.getBytes());
        return md.digest();
    }
806485
@Override
    public TextMessage createTextMessage() throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createTextMessage");

        TextMessage textMessage = null;

        try {
            textMessage = jmsSession.createTextMessage();
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createTextMessage", new Object[] { textMessage });
        }

        return textMessage;

    }
208248
public BeanInvocation sayHello(String message) {
        BeanInvocation invocation = new BeanInvocation();
        try {
            invocation.setMethod(HelloService.class.getMethod("sayHello", String.class));
            invocation.setArgs(new Object[] { message });
        } catch (NoSuchMethodException e) {
            throw new CitrusRuntimeException("Failed to access remote service method", e);
        }
        return invocation;
    }
476319
public String generateDigest(InputStream stream) {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance(DIGEST_ALGORITHM_SHA1);
        } catch (NoSuchAlgorithmException ae) {
            throw new BoxAPIException("Digest algorithm not found", ae);
        }

        //Calcuate the digest using the stream.
        DigestInputStream dis = new DigestInputStream(stream, digest);
        try {
            int value = dis.read();
            while (value != -1) {
                value = dis.read();
            }
        } catch (IOException ioe) {
            throw new BoxAPIException("Reading the stream failed.", ioe);
        }

        //Get the calculated digest for the stream
        byte[] digestBytes = digest.digest();
        return Base64.encode(digestBytes);
    }
630701
private static byte[] digest(@NotNull byte[] input, MessageDigest digest, byte[] salt, int iterations) {
		// 带盐
		if (salt != null) {
			digest.update(salt);
		}

		// 第一次散列
		byte[] result = digest.digest(input);

		// 如果迭代次数>1，进一步迭代散列
		for (int i = 1; i < iterations; i++) {
			digest.reset();
			result = digest.digest(result);
		}

		return result;
	}
1306582
public static void nailMain(NGContext context)
      throws java.security.NoSuchAlgorithmException, java.io.IOException {
    String[] args = context.getArgs();

    if (args.length == 0) {
      // display available algorithms
      Set algs = getCryptoImpls("MessageDigest");
      for (Object alg : algs) {
        context.out.println(alg);
      }
      return;
    }

    // perform the actual hash.  throw any exceptions back to the user.
    MessageDigest md = MessageDigest.getInstance(args[0]);

    byte[] b = new byte[1024];
    int bytesRead = context.in.read(b);
    while (bytesRead != -1) {
      md.update(b, 0, bytesRead);
      bytesRead = System.in.read(b);
    }
    byte[] result = md.digest();

    // convert hash result to a string of hex characters and print it to the client.
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < result.length; ++i) {
      buf.append(HEXCHARS[(result[i] >> 4) & 0x0f]);
      buf.append(HEXCHARS[result[i] & 0x0f]);
    }
    context.out.println(buf);
  }
1101093
public void processMessage(JsMessage jsMsg) throws SIResourceException
   {
     if (tc.isEntryEnabled())
       SibTr.entry(tc, "processMessage", new Object[] { jsMsg });
    
     int priority = jsMsg.getPriority().intValue();
     Reliability reliability = jsMsg.getReliability();
       
     SIBUuid12 streamID = jsMsg.getGuaranteedStreamUUID();
     StreamSet streamSet = getStreamSet(streamID, true);
     
     InternalInputStream internalInputStream = null;
     synchronized(streamSet)
     {
       internalInputStream = (InternalInputStream) streamSet.getStream(priority, reliability);        

       // This may be the first message which has required this stream    
       if(internalInputStream == null && 
        (reliability.compareTo(Reliability.BEST_EFFORT_NONPERSISTENT) > 0))
       {
         internalInputStream = createStream(streamSet, priority, reliability);      
       }
     }
        
     if (tc.isEntryEnabled())
       SibTr.exit(tc, "processMessage");
   }
316932
private static byte[] digest(final byte[] input, final String algorithm, final byte[] salt, final int iterations) {
		try {
			MessageDigest digest = MessageDigest.getInstance(algorithm);

			if (salt != null) {
				digest.update(salt);
			}

			byte[] result = digest.digest(input);

			for (int i = 1; i < iterations; i++) {
				digest.reset();
				result = digest.digest(result);
			}
			return result;
		} catch (NoSuchAlgorithmException e) {
			throw new ImpossibleException(e);
		}
	}
1260908
static byte []
generateDSDigest(DNSKEYRecord key, int digestid)
{
	MessageDigest digest;
	try {
		switch (digestid) {
		case DSRecord.Digest.SHA1:
			digest = MessageDigest.getInstance("sha-1");
			break;
		case DSRecord.Digest.SHA256:
			digest = MessageDigest.getInstance("sha-256");
			break;
		case DSRecord.Digest.GOST3411:
			digest = MessageDigest.getInstance("GOST3411");
			break;
		case DSRecord.Digest.SHA384:
			digest = MessageDigest.getInstance("sha-384");
			break;
		default:
			throw new IllegalArgumentException(
					"unknown DS digest type " + digestid);
		}
	}
	catch (NoSuchAlgorithmException e) {
		throw new IllegalStateException("no message digest support");
	}
	digest.update(key.getName().toWireCanonical());
	digest.update(key.rdataToWireCanonical());
	return digest.digest();
}
440906
public BaseMessage processMessage(BaseMessage internalMessage)
    {
        if (internalMessage.getMessageDataDesc(null) == null)
            internalMessage.addMessageDataDesc(new RunRemoteProcessMessageData(null, null));
        
        RunRemoteProcessMessageData runRemoteProcessMessageData = (RunRemoteProcessMessageData)internalMessage.getMessageDataDesc(null);
        String processClassName = (String)runRemoteProcessMessageData.get(RunRemoteProcessMessageData.PROCESS_CLASS_NAME);
        if (processClassName == null)
        	return null;
        
        BaseProcess process = null;
        Task task = this.getTask();
        Map<String,Object> properties = new HashMap<String,Object>();
        MapMessage.convertDOMtoMap(internalMessage.getDOM(), properties, true);
        process = (BaseProcess)ClassServiceUtility.getClassService().makeObjectFromClassName(processClassName);
        if (process == null)
        	return null;
        process.init(task, null, properties);
        
        BaseMessage messageReply = null;
        if (process instanceof BaseMessageProcess)
        	messageReply = ((BaseMessageProcess)process).processMessage(internalMessage);
        else
        	process.run();
      
        return messageReply;
    }
923819
protected void cachePrincipal(String apiKey, Principal principal) {
        cache.put(apiKey, Optional.fromNullable(principal));
    }
1131032
@Nullable
    static String shaHashInput(@Nullable String toHash) {
        if (StripeTextUtils.isBlank(toHash)) {
            return null;
        }

        try {
            final MessageDigest digest = MessageDigest.getInstance("SHA-1");
            final byte[] bytes = toHash.getBytes("UTF-8");
            digest.update(bytes, 0, bytes.length);
            return bytesToHex(digest.digest());
        } catch (NoSuchAlgorithmException noSuchAlgorithm) {
            return null;
        } catch (UnsupportedEncodingException unsupportedCoding) {
            return null;
        }
    }
404175
public ServerBuilder service(PathMapping pathMapping, Service<HttpRequest, HttpResponse> service) {
        defaultVirtualHostBuilderUpdated();
        defaultVirtualHostBuilder.service(pathMapping, service);
        return this;
    }
118901
protected synchronized MessageDigest getDigest() {
        if (this.digest == null) {
            try {
                this.digest = MessageDigest.getInstance(algorithm);
            } catch (NoSuchAlgorithmException e) {
                try {
                    this.digest = MessageDigest.getInstance(DEFAULT_ALGORITHM);
                } catch (NoSuchAlgorithmException f) {
                    this.digest = null;
                }
            }
        }
        return (this.digest);
    }
216328
public Optional<SecurityToken> fetch(final Service service, final String principalId) {
        val resolvedService = this.selectionStrategy.resolveServiceFrom(service);
        LOGGER.debug("Resolved resolvedService as [{}]", resolvedService);
        if (resolvedService != null) {
            val rp = this.servicesManager.findServiceBy(resolvedService, WSFederationRegisteredService.class);
            if (rp == null || !rp.getAccessStrategy().isServiceAccessAllowed()) {
                LOGGER.warn("Service [{}] is not allowed to use SSO.", rp);
                throw new UnauthorizedSsoServiceException();
            }
            LOGGER.debug("Building security token resolvedService client for registered resolvedService [{}]", rp);
            val sts = clientBuilder.buildClientForSecurityTokenRequests(rp);
            return Optional.ofNullable(invokeSecurityTokenServiceForToken(rp, sts, principalId));
        }
        return Optional.empty();
    }
412123
static void ensurePrincipalAccessIsAllowedForService(final Service service,
                                                         final RegisteredService registeredService,
                                                         final String principalId,
                                                         final Map<String, Object> attributes) {
        ensureServiceAccessIsAllowed(service, registeredService);
        if (!registeredService.getAccessStrategy().doPrincipalAttributesAllowServiceAccess(principalId, attributes)) {
            LOGGER.warn("Cannot grant access to service [{}] because it is not authorized for use by [{}].", service.getId(), principalId);
            val handlerErrors = new HashMap<String, Throwable>();
            val message = String.format("Cannot grant service access to %s", principalId);
            val exception = new UnauthorizedServiceForPrincipalException(message, registeredService, principalId, attributes);
            handlerErrors.put(UnauthorizedServiceForPrincipalException.class.getSimpleName(), exception);

            throw new PrincipalException(UnauthorizedServiceForPrincipalException.CODE_UNAUTHZ_SERVICE, handlerErrors, new HashMap<>());
        }
    }