org.apache.tomcat.util.codec.binary.Base64类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(543)

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

Base64介绍

[英]Provides Base64 encoding and decoding as defined by RFC 2045.

This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein.

The class can be parameterized in the following manner with various constructors:

  • URL-safe mode: Default off.
  • Line length: Default 76. Line length that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
  • Line separator: Default is CRLF ("\r\n")

Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).

This class is thread-safe.
[中]提供由RFC 2045定义的Base64编码和解码。
此类实现了第6.8节。RFC 2045多用途Internet邮件扩展(MIME)的Base64内容传输编码第一部分:Freed和Borenstein的Internet邮件正文格式。
该类可以通过以下方式使用各种构造函数进行参数化:
*URL安全模式:默认关闭。
*行长度:默认为76。在编码数据中,不是4的倍数的行长度实际上仍然是4的倍数。
*行分隔符:默认为CRLF(“\r\n”)
由于该类直接对字节流而不是字符流进行操作,因此它被硬编码为仅对与较低的127 ASCII图表(ISO-8859-1、Windows-1252、UTF-8等)兼容的字符编码进行编码/解码。
这个类是线程安全的。

代码示例

代码示例来源:origin: wangxinforme/springboot-freemarker

/**
 * Base64编码.
 */
public static String encodeBase64(byte[] input) {
  return Base64.encodeBase64String(input);
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Decodes Base64 data into octets
 *
 * @param base64Data
 *            Byte array containing Base64 data
 * @return Array containing decoded data.
 */
public static byte[] decodeBase64(final byte[] base64Data) {
  return decodeBase64(base64Data, 0, base64Data.length);
}

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

/**
 * Encodes binary data using the base64 algorithm but does not chunk the output.
 *
 * @param binaryData
 *            binary data to encode
 * @return byte[] containing Base64 characters in their UTF-8 representation.
 */
public static byte[] encodeBase64(final byte[] binaryData) {
  return encodeBase64(binaryData, false);
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Decodes a Base64 String into octets
 *
 * @param base64String
 *            String containing Base64 data
 * @return Array containing decoded data.
 * @since 1.4
 */
public static byte[] decodeBase64(final String base64String) {
  return new Base64().decode(base64String);
}

代码示例来源:origin: codefollower/Tomcat-Research

/**
 * Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
 *
 * @param bigInt
 *            a BigInteger
 * @return A byte array containing base64 character data
 * @throws NullPointerException
 *             if null is passed in
 * @since 1.4
 */
public static byte[] encodeInteger(final BigInteger bigInt) {
  if (bigInt == null) {
    throw new NullPointerException("encodeInteger called with null parameter");
  }
  return encodeBase64(toIntegerBytes(bigInt), false);
}

代码示例来源:origin: codefollower/Tomcat-Research

final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
final long len = b64.getEncodedLength(binaryData);
if (len > maxResultSize) {
  throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
return b64.encode(binaryData);

代码示例来源:origin: codefollower/Tomcat-Research

md.reset();
  md.update(userCredentials.getBytes(StandardCharsets.ISO_8859_1));
  userDigest = Base64.encodeBase64String(md.digest());
    Base64.decodeBase64(serverDigestPlusSalt);
final int saltPos = 20;
byte[] serverDigestBytes = new byte[saltPos];

代码示例来源:origin: codefollower/Tomcat-Research

final byte[] buffer = ensureBufferSize(decodeSize, context);
final byte b = in[inPos++];
if (b == PAD) {
final byte[] buffer = ensureBufferSize(decodeSize, context);

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

if (containsAlphabetOrPad(lineSeparator)) {
  final String sep = StringUtils.newStringUtf8(lineSeparator);
  throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");

代码示例来源:origin: org.apache.tomcat/tomcat-catalina

String userDigest = Base64.encodeBase64String(ConcurrentMessageDigest.digest(
    getAlgorithm(), inputCredentials.getBytes(StandardCharsets.ISO_8859_1)));
return userDigest.equals(serverDigest);
    Base64.decodeBase64(serverDigestPlusSalt);
final int saltPos = 20;
byte[] serverDigestBytes = new byte[saltPos];

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

final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
final long len = b64.getEncodedLength(binaryData);
if (len > maxResultSize) {
  throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
return b64.encode(binaryData);

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

/**
 * Decodes a Base64 String into octets
 *
 * @param base64String
 *            String containing Base64 data
 * @return Array containing decoded data.
 * @since 1.4
 */
public static byte[] decodeBase64(final String base64String) {
  return new Base64().decode(base64String);
}

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

/**
 * Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
 *
 * @param bigInt
 *            a BigInteger
 * @return A byte array containing base64 character data
 * @throws NullPointerException
 *             if null is passed in
 * @since 1.4
 */
public static byte[] encodeInteger(final BigInteger bigInt) {
  if (bigInt == null) {
    throw new NullPointerException("encodeInteger called with null parameter");
  }
  return encodeBase64(toIntegerBytes(bigInt), false);
}

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

final byte[] buffer = ensureBufferSize(decodeSize, context);
final byte b = in[inPos++];
if (b == PAD) {
final byte[] buffer = ensureBufferSize(decodeSize, context);

代码示例来源:origin: codefollower/Tomcat-Research

if (containsAlphabetOrPad(lineSeparator)) {
  final String sep = StringUtils.newStringUtf8(lineSeparator);
  throw new IllegalArgumentException("lineSeparator must not contain base64 characters: [" + sep + "]");

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

String userDigest = Base64.encodeBase64String(ConcurrentMessageDigest.digest(
    getAlgorithm(), inputCredentials.getBytes(StandardCharsets.ISO_8859_1)));
return userDigest.equals(serverDigest);
    Base64.decodeBase64(serverDigestPlusSalt);
final int saltPos = 20;
byte[] serverDigestBytes = new byte[saltPos];

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

/**
 * Decodes Base64 data into octets
 *
 * @param base64Data
 *            Byte array containing Base64 data
 * @return Array containing decoded data.
 */
public static byte[] decodeBase64(final byte[] base64Data) {
  return decodeBase64(base64Data, 0, base64Data.length);
}

代码示例来源:origin: org.apache.tomcat/tomcat-websocket

private static String generateWsKeyValue() {
  byte[] keyBytes = new byte[16];
  RANDOM.nextBytes(keyBytes);
  return Base64.encodeBase64String(keyBytes);
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/util

/**
 * Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
 * url-safe variation emits - and _ instead of + and / characters.
 * <b>Note: no padding is added.</b>
 * @param binaryData
 *            binary data to encode
 * @return byte[] containing Base64 characters in their UTF-8 representation.
 * @since 1.4
 */
public static byte[] encodeBase64URLSafe(final byte[] binaryData) {
  return encodeBase64(binaryData, false, true);
}

代码示例来源:origin: org.apache.geronimo.ext.tomcat/util

final Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
final long len = b64.getEncodedLength(binaryData);
if (len > maxResultSize) {
  throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
return b64.encode(binaryData);

相关文章