org.apache.catalina.authenticator.AuthenticatorBase.getDigest()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.apache.catalina.authenticator.AuthenticatorBase.getDigest()方法的一些代码示例,展示了AuthenticatorBase.getDigest()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AuthenticatorBase.getDigest()方法的具体详情如下:
包路径:org.apache.catalina.authenticator.AuthenticatorBase
类名称:AuthenticatorBase
方法名:getDigest

AuthenticatorBase.getDigest介绍

[英]Return the MessageDigest object to be used for calculating session identifiers. If none has been created yet, initialize one the first time this method is called.
[中]返回用于计算会话标识符的MessageDigest对象。如果尚未创建任何对象,请在第一次调用此方法时初始化一个对象。

代码示例

代码示例来源:origin: jboss.web/jbossweb

/**
 * Generate and return a new session identifier for the cookie that
 * identifies an SSO principal.
 */
protected synchronized String generateSessionId() {
  // Generate a byte array containing a session identifier
  byte bytes[] = new byte[SESSION_ID_BYTES];
  getRandom().nextBytes(bytes);
  bytes = getDigest().digest(bytes);
  // Render the result as a String of hexadecimal digits
  StringBuilder result = new StringBuilder();
  for (int i = 0; i < bytes.length; i++) {
    byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
    byte b2 = (byte) (bytes[i] & 0x0f);
    if (b1 < 10)
      result.append((char) ('0' + b1));
    else
      result.append((char) ('A' + (b1 - 10)));
    if (b2 < 10)
      result.append((char) ('0' + b2));
    else
      result.append((char) ('A' + (b2 - 10)));
  }
  return (result.toString());
}

代码示例来源:origin: tomcat/catalina

/**
 * Generate and return a new session identifier for the cookie that
 * identifies an SSO principal.
 */
protected synchronized String generateSessionId() {
  // Generate a byte array containing a session identifier
  byte bytes[] = new byte[SESSION_ID_BYTES];
  getRandom().nextBytes(bytes);
  bytes = getDigest().digest(bytes);
  // Render the result as a String of hexadecimal digits
  StringBuffer result = new StringBuffer();
  for (int i = 0; i < bytes.length; i++) {
    byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
    byte b2 = (byte) (bytes[i] & 0x0f);
    if (b1 < 10)
      result.append((char) ('0' + b1));
    else
      result.append((char) ('A' + (b1 - 10)));
    if (b2 < 10)
      result.append((char) ('0' + b2));
    else
      result.append((char) ('A' + (b2 - 10)));
  }
  return (result.toString());
}

相关文章

微信公众号

最新文章

更多