org.apache.shiro.codec.Hex.encode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(154)

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

Hex.encode介绍

[英]Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. The returned array will be double the length of the passed array, as it takes two characters to represent any given byte.
[中]将字节数组转换为按顺序表示每个字节的十六进制值的字符数组。返回的数组的长度将是传递的数组的两倍,因为它需要两个字符来表示任何给定的字节。

代码示例

代码示例来源:origin: apache/shiro

/**
 * Encodes the specified byte array to a character array and then returns that character array
 * as a String.
 *
 * @param bytes the byte array to Hex-encode.
 * @return A String representation of the resultant hex-encoded char array.
 */
public static String encodeToString(byte[] bytes) {
  char[] encodedChars = encode(bytes);
  return new String(encodedChars);
}

代码示例来源:origin: org.apache.shiro/shiro-lang

/**
 * Encodes the specified byte array to a character array and then returns that character array
 * as a String.
 *
 * @param bytes the byte array to Hex-encode.
 * @return A String representation of the resultant hex-encoded char array.
 */
public static String encodeToString(byte[] bytes) {
  char[] encodedChars = encode(bytes);
  return new String(encodedChars);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Encodes the specifed byte array to a character array and then returns that character array
 * as a String.
 *
 * @param bytes the byte array to Hex-encode.
 * @return A String representation of the resultant hex-encoded char array.
 */
public static String encodeToString(byte[] bytes) {
  char[] encodedChars = encode(bytes);
  return new String(encodedChars);
}

代码示例来源:origin: org.sonatype.nexus/nexus-ldap-common

protected String encodeString(String input) {
 InputStream is = new ByteArrayInputStream(input.getBytes());
 String result = null;
 try {
  byte[] buffer = new byte[1024];
  MessageDigest md5 = MessageDigest.getInstance("MD5");
  int numRead;
  do {
   numRead = is.read(buffer);
   if (numRead > 0) {
    md5.update(buffer, 0, numRead);
   }
  }
  while (numRead != -1);
  result = new String(Hex.encode(md5.digest()));
 }
 catch (Exception e) {
 }
 return result;
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 String filename = (String) request.getParameter(FILE);
 String signature = (String) request.getParameter(SIGNATURE);
 
 boolean isValid = validate(filename, signature);
 
 response.setContentType("text/html");
 response.setStatus(HttpServletResponse.SC_OK);
 
 response.getWriter().println("<h1>Hello SimpleServlet</h1>");
 response.getWriter().println("filename: "+ filename + "<br>");
 response.getWriter().println("signature: "+ signature + "<br>");
 response.getWriter().println("expected: "+ new String(Hex.encode(expectedSignature(filename))) + "<br>");
 response.getWriter().println("<br>");
 response.getWriter().println("validity: "+ isValid + "<br>");
}

代码示例来源:origin: SomMeri/matasano-cryptopals-solutions

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 String filename = (String) request.getParameter(FILE);
 String signature = (String) request.getParameter(SIGNATURE);
 
 boolean isValid = validate(filename, signature);
 
 response.setContentType("text/html");
 response.setStatus(HttpServletResponse.SC_OK);
 
 response.getWriter().println("<h1>Hello SimpleServlet</h1>");
 response.getWriter().println("filename: "+ filename + "<br>");
 response.getWriter().println("signature: "+ signature + "<br>");
 response.getWriter().println("expected: "+ new String(Hex.encode(expectedSignature(filename))) + "<br>");
 response.getWriter().println("<br>");
 response.getWriter().println("validity: "+ isValid + "<br>");
}

代码示例来源:origin: org.sonatype.nexus.plugins.ldap/ldap-common

protected String encodeString( String input )
{
  InputStream is = new ByteArrayInputStream( input.getBytes() );
  String result = null;
  try
  {
    byte[] buffer = new byte[1024];
    MessageDigest md5 = MessageDigest.getInstance( "MD5" );
    int numRead;
    do
    {
      numRead = is.read( buffer );
      if ( numRead > 0 )
      {
        md5.update( buffer, 0, numRead );
      }
    }
    while ( numRead != -1 );
    result = new String( Hex.encode( md5.digest() ) );
  }
  catch ( Exception e )
  {
  }
  return result;
}

代码示例来源:origin: com.walmartlabs.concord.server/concord-server

mac.init(signingKey);
byte[] digest = mac.doFinal(payload);
String digestHex = String.valueOf(Hex.encode(digest));

相关文章