org.glassfish.jersey.internal.util.Base64.encodeAsString()方法的使用及代码示例

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

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

Base64.encodeAsString介绍

[英]Encodes a string using base64 and returns the result as another string.
[中]使用base64对字符串进行编码,并将结果作为另一个字符串返回。

代码示例

代码示例来源:origin: jersey/jersey

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: jersey/jersey

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: confluentinc/ksql

private static String buildBasicAuthHeader(final String userName, final String password) {
 return Base64.encodeAsString(userName + ":" + password);
}

代码示例来源:origin: jersey/jersey

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: jersey/jersey

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: org.glassfish.jersey.core/jersey-client

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: jersey/jersey

static String generateAuthorizationHeader(String userName, String password) throws ProxyAuthenticationException {
    if (userName == null) {
      throw new ProxyAuthenticationException(LocalizationMessages.PROXY_USER_NAME_MISSING());
    }

    if (password == null) {
      throw new ProxyAuthenticationException(LocalizationMessages.PROXY_PASSWORD_MISSING());
    }

    byte[] prefix = (userName + ":").getBytes(CHARACTER_SET);
    byte[] passwordBytes = password.getBytes(CHARACTER_SET);
    byte[] usernamePassword = new byte[prefix.length + passwordBytes.length];

    System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
    System.arraycopy(passwordBytes, 0, usernamePassword, prefix.length, passwordBytes.length);

    return "Basic " + Base64.encodeAsString(usernamePassword);
  }
}

代码示例来源:origin: ff4j/ff4j

/**
 * Build Authorization header for final user.
 * @param username
 *      target username
 * @param password
 *      target password
 * @return
 *      target header
 */
public static String buildAuthorization4UserName(String username, String password) {
  return " Basic " + new String(Base64.encodeAsString(username + ":" + password));
}

代码示例来源:origin: ff4j/ff4j

/**
 * Build Authorization header for final user.
 * @param username target username
 * @param password target password
 * @return target header
 */
public static String buildAuthorization4UserName(String username, String password) {
  return " Basic " + new String(Base64.encodeAsString(username + ":" + password));
}

代码示例来源:origin: org.glassfish.jersey.bundles/jaxrs-ri

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: org.glassfish.jersey.core/jersey-common

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Encodes a string using base64 and returns the result as another string.
 *
 * @param text String to be encoded.
 * @return Resulting encoded string.
 */
public static String encodeAsString(final String text) {
  return encodeAsString(text.getBytes());
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: org.glassfish.jersey.bundles/jaxrs-ri

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

private String calculateAuthentication(HttpAuthenticationFilter.Credentials credentials) {
  String username = credentials.getUsername();
  byte[] password = credentials.getPassword();
  if (username == null) {
    username = "";
  }
  if (password == null) {
    password = new byte[0];
  }
  final byte[] prefix = (username + ":").getBytes(HttpAuthenticationFilter.CHARACTER_SET);
  final byte[] usernamePassword = new byte[prefix.length + password.length];
  System.arraycopy(prefix, 0, usernamePassword, 0, prefix.length);
  System.arraycopy(password, 0, usernamePassword, prefix.length, password.length);
  return "Basic " + Base64.encodeAsString(usernamePassword);
}

代码示例来源:origin: igniterealtime/REST-API-Client

/**
 * Authentication token.
 *
 * @param token
 *            the token
 * @return the rest client builder
 */
public RestClientBuilder authenticationToken(AuthenticationToken token) {
  if (token.getAuthMode() == AuthenticationMode.SHARED_SECRET_KEY) {
    headers.add(HttpHeaders.AUTHORIZATION, token.getSharedSecretKey());
  } else if (token.getAuthMode() == AuthenticationMode.BASIC_AUTH) {
    String base64 = Base64.encodeAsString(token.getUsername() + ":" + token.getPassword());
    headers.add(HttpHeaders.AUTHORIZATION, "Basic " + base64);
  }
  this.token = token;
  return this;
}

代码示例来源:origin: heroku/heroku.jar

final Invocation.Builder builder = client.target(ENDPOINT.value + request.getEndpoint()).request();
builder.header("Authorization", Base64.encodeAsString((":" + apiKey).getBytes()));
builder.header(request.getResponseType().getHeaderName(), request.getResponseType().getHeaderValue());
builder.header(Heroku.ApiVersion.v3.getHeaderName(), Heroku.ApiVersion.v3.getHeaderValue());

相关文章