org.springframework.security.crypto.codec.Base64.decode()方法的使用及代码示例

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

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

Base64.decode介绍

[英]Low-level access to decoding ASCII characters in the form of a byte array. Ignores GUNZIP option, if it's set. This is not generally a recommended method, although it is used internally as part of the decoding process. Special case: if len = 0, an empty array is returned. Still, if you need more speed and reduced memory footprint (and aren't gzipping), consider this method.
[中]对字节数组形式的ASCII字符进行解码的低级访问。忽略GUNZIP选项(如果已设置)。这通常不是推荐的方法,尽管它在内部用作解码过程的一部分。特殊情况:如果len=0,则返回空数组。不过,如果你需要更多的速度和减少内存占用(而不是GZIPIP),请考虑这个方法。

代码示例

代码示例来源:origin: spring-projects/spring-security

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: spring-projects/spring-security

public static byte[] decode(byte[] bytes) {
  return decode(bytes, 0, bytes.length, NO_OPTIONS);
}

代码示例来源:origin: org.springframework.security/spring-security-core

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.springframework.security/spring-security-core

public static byte[] decode(byte[] bytes) {
  return decode(bytes, 0, bytes.length, NO_OPTIONS);
}

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

@Override
public String decompressLogLine(String compressedFromLog) throws IOException {
  String fixed = compressedFromLog;
  if (fixed.contains(":")) {
    fixed = fixed.substring(fixed.indexOf(":") + 1, fixed.length());
  }
  fixed = fixed.trim();
  return CompressedItem.decompress(Base64.decode(fixed.getBytes()));
}

代码示例来源:origin: cloudfoundry/uaa

private String[] extractAndDecodeHeader(String header, HttpServletRequest request)
      throws IOException {

    byte[] base64Token = header.substring(6).getBytes("UTF-8");
    byte[] decoded;
    try {
      decoded = Base64.decode(base64Token);
    }
    catch (IllegalArgumentException e) {
      throw new BadCredentialsException(
          "Failed to decode basic authentication token");
    }

    String token = new String(decoded, getCredentialsCharset(request));

    int delim = token.indexOf(":");

    if (delim == -1) {
      throw new BadCredentialsException("Invalid basic authentication token");
    }
    return new String[] { token.substring(0, delim), token.substring(delim + 1) };
  }
}

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

@Override
public boolean isPasswordValid(String encPass, char[] rawPass, Object salt) {
  byte[] decoded = Base64.decode(encPass.getBytes());
  byte[] decrypted = byteEncrypter.decrypt(decoded);
  char[] chars = toChars(decrypted);
  try {
    return Arrays.equals(chars, rawPass);
  } finally {
    scramble(decrypted);
    scramble(chars);
  }
}

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

throw new RuntimeException(e1);
String token = new String(Base64.decode(base64Token));

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

public Authentication validateKerberosTicket(HttpServletRequest request) {
  // Only support Kerberos login when running securely
  if (!request.isSecure()) {
    return null;
  }
  String header = request.getHeader(AUTHORIZATION_HEADER_NAME);
  if (isValidKerberosHeader(header)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Received Negotiate Header for request " + request.getRequestURL() + ": " + header);
    }
    byte[] base64Token = header.substring(header.indexOf(" ") + 1).getBytes(StandardCharsets.UTF_8);
    byte[] kerberosTicket = Base64.decode(base64Token);
    KerberosServiceRequestToken authenticationRequest = new KerberosServiceRequestToken(kerberosTicket);
    authenticationRequest.setDetails(authenticationDetailsSource.buildDetails(request));
    return kerberosServiceAuthenticationProvider.authenticate(authenticationRequest);
  } else {
    return null;
  }
}

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

@Override
public char[] decodeToCharArray(String encPass) throws UnsupportedOperationException {
  if (byteEncrypter == null) {
    // not initialized
    getCharEncoder();
  }
  byte[] decoded = Base64.decode(removePrefix(encPass).getBytes());
  byte[] bytes = byteEncrypter.decrypt(decoded);
  try {
    return toChars(bytes);
  } finally {
    scramble(bytes);
  }
}

代码示例来源:origin: cloudfoundry/uaa

String credentials = new String(new Base64().decode(base64Credentials.getBytes()), UTF_8.name());

代码示例来源:origin: pig4cloud/pig

/**
 * 从header 请求中的clientId/clientsecect
 *
 * @param header header中的参数
 * @throws CheckedException if the Basic header is not present or is not valid
 *                          Base64
 */
public static String[] extractAndDecodeHeader(String header)
    throws IOException {
  byte[] base64Token = header.substring(6).getBytes("UTF-8");
  byte[] decoded;
  try {
    decoded = Base64.decode(base64Token);
  } catch (IllegalArgumentException e) {
    throw new CheckedException(
        "Failed to decode basic authentication token");
  }
  String token = new String(decoded, CommonConstant.UTF8);
  int delim = token.indexOf(":");
  if (delim == -1) {
    throw new CheckedException("Invalid basic authentication token");
  }
  return new String[]{token.substring(0, delim), token.substring(delim + 1)};
}

代码示例来源:origin: org.springframework.security/spring-security-crypto

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.springframework.security/org.springframework.security.core

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  } catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.springframework.security/spring-security-crypto

public static byte[] decode(byte[] bytes) {
  return decode(bytes, 0, bytes.length, NO_OPTIONS);
}

代码示例来源:origin: com.bushidowallet/bushido-core-lib

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: apache/servicemix-bundles

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: apache/servicemix-bundles

public static boolean isBase64(byte[] bytes) {
  try {
    decode(bytes);
  }
  catch (InvalidBase64CharacterException e) {
    return false;
  }
  return true;
}

代码示例来源:origin: org.springframework.security/org.springframework.security.core

private byte[] extractSalt(String encPass) {
  String encPassNoLabel = encPass.substring(6);
  byte[] hashAndSalt = Base64.decode(encPassNoLabel.getBytes());
  int saltLength = hashAndSalt.length - SHA_LENGTH;
  byte[] salt = new byte[saltLength];
  System.arraycopy(hashAndSalt, SHA_LENGTH, salt, 0, saltLength);
  return salt;
}

代码示例来源:origin: com.bushidowallet/bushido-core-lib

public String decrypt(String encryptedText, SecretKey secretKey)
      throws Exception {
    byte[] encryptedTextByte = Base64.decode(encryptedText.getBytes());
    cipher.init(Cipher.DECRYPT_MODE, secretKey);
    byte[] decryptedByte = cipher.doFinal(encryptedTextByte);
    String decryptedText = new String(decryptedByte);
    return decryptedText;
  }
}

相关文章