org.springframework.security.crypto.codec.Utf8类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(159)

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

Utf8介绍

[英]UTF-8 Charset encoder/decoder.

For internal use only.
[中]UTF-8字符集编码器/解码器。
仅供内部使用。

代码示例

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

private static byte[] bytesUtf8(String s) {
  if (s == null) {
    return null;
  }
  return Utf8.encode(s); // need to check if Utf8.encode() runs in constant time (probably not). This may leak length of string.
}

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

private String encode(CharSequence rawPassword, byte[] salt) {
  MessageDigest sha;
  try {
    sha = MessageDigest.getInstance("SHA");
    sha.update(Utf8.encode(rawPassword));
  }
  catch (java.security.NoSuchAlgorithmException e) {
    throw new IllegalStateException("No SHA implementation available!");
  }
  if (salt != null) {
    sha.update(salt);
  }
  byte[] hash = combineHashAndSalt(sha.digest(), (byte[]) salt);
  String prefix;
  if (salt == null || salt.length == 0) {
    prefix = forceLowerCasePrefix ? SHA_PREFIX_LC : SHA_PREFIX;
  }
  else {
    prefix = forceLowerCasePrefix ? SSHA_PREFIX_LC : SSHA_PREFIX;
  }
  return prefix + Utf8.decode(Base64.getEncoder().encode(hash));
}

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

private String encodePart(byte[] part) {
    return Utf8.decode(Base64.getEncoder().encode(part));
  }
}

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

public static String convertPasswordToString(Object passObj) {
  Assert.notNull(passObj, "Password object to convert must not be null");
  if (passObj instanceof byte[]) {
    return Utf8.decode((byte[]) passObj);
  }
  else if (passObj instanceof String) {
    return (String) passObj;
  }
  else {
    throw new IllegalArgumentException(
        "Password object was not a String or byte array.");
  }
}

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

/**
 * Constructs a standard password encoder with a secret value as well as iterations
 * and hash.
 *
 * @param secret the secret
 * @param iterations the number of iterations. Users should aim for taking about .5
 * seconds on their own system.
 * @param hashWidth the size of the hash
 */
public Pbkdf2PasswordEncoder(CharSequence secret, int iterations, int hashWidth) {
  this.secret = Utf8.encode(secret);
  this.iterations = iterations;
  this.hashWidth = hashWidth;
}

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

public Token allocateToken(String extendedInformation) {
  Assert.notNull(extendedInformation,
      "Must provided non-null extendedInformation (but it can be empty)");
  long creationTime = new Date().getTime();
  String serverSecret = computeServerSecretApplicableAt(creationTime);
  String pseudoRandomNumber = generatePseudoRandomNumber();
  String content = Long.toString(creationTime) + ":" + pseudoRandomNumber + ":"
      + extendedInformation;
  // Compute key
  String sha512Hex = Sha512DigestUtils.shaHex(content + ":" + serverSecret);
  String keyPayload = content + ":" + sha512Hex;
  String key = Utf8.decode(Base64.getEncoder().encode(Utf8.encode(keyPayload)));
  return new DefaultToken(key, creationTime, extendedInformation);
}

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

private String encodePart(byte[] part) {
    return Utf8.decode(Base64.getEncoder().encode(part));
  }
}

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

private static byte[] bytesUtf8(String s) {
  if (s == null) {
    return null;
  }
  return Utf8.encode(s); // need to check if Utf8.encode() runs in constant time (probably not). This may leak length of string.
}

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

private String encode(CharSequence rawPassword, byte[] salt) {
  MessageDigest sha;
  try {
    sha = MessageDigest.getInstance("SHA");
    sha.update(Utf8.encode(rawPassword));
  }
  catch (java.security.NoSuchAlgorithmException e) {
    throw new IllegalStateException("No SHA implementation available!");
  }
  if (salt != null) {
    sha.update(salt);
  }
  byte[] hash = combineHashAndSalt(sha.digest(), (byte[]) salt);
  String prefix;
  if (salt == null || salt.length == 0) {
    prefix = forceLowerCasePrefix ? SHA_PREFIX_LC : SHA_PREFIX;
  }
  else {
    prefix = forceLowerCasePrefix ? SSHA_PREFIX_LC : SSHA_PREFIX;
  }
  return prefix + Utf8.decode(Base64.getEncoder().encode(hash));
}

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

private String encode(byte[] digest) {
  if (this.encodeHashAsBase64) {
    return Utf8.decode(Base64.getEncoder().encode(digest));
  }
  else {
    return new String(Hex.encode(digest));
  }
}

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

/**
 * Constructs a standard password encoder with a secret value as well as iterations
 * and hash.
 *
 * @param secret the secret
 * @param iterations the number of iterations. Users should aim for taking about .5
 * seconds on their own system.
 * @param hashWidth the size of the hash
 */
public Pbkdf2PasswordEncoder(CharSequence secret, int iterations, int hashWidth) {
  this.secret = Utf8.encode(secret);
  this.iterations = iterations;
  this.hashWidth = hashWidth;
}

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

public Token allocateToken(String extendedInformation) {
  Assert.notNull(extendedInformation,
      "Must provided non-null extendedInformation (but it can be empty)");
  long creationTime = new Date().getTime();
  String serverSecret = computeServerSecretApplicableAt(creationTime);
  String pseudoRandomNumber = generatePseudoRandomNumber();
  String content = Long.toString(creationTime) + ":" + pseudoRandomNumber + ":"
      + extendedInformation;
  // Compute key
  String sha512Hex = Sha512DigestUtils.shaHex(content + ":" + serverSecret);
  String keyPayload = content + ":" + sha512Hex;
  String key = Utf8.decode(Base64.getEncoder().encode(Utf8.encode(keyPayload)));
  return new DefaultToken(key, creationTime, extendedInformation);
}

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

private String encode(byte[] digest) {
  if (this.encodeHashAsBase64) {
    return Utf8.decode(Base64.getEncoder().encode(digest));
  }
  else {
    return new String(Hex.encode(digest));
  }
}

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

private byte[] decodePart(String part) {
  return Base64.getDecoder().decode(Utf8.encode(part));
}

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

Utf8.decode(Base64.getDecoder().decode(Utf8.encode(key))), ":");
Assert.isTrue(tokens.length >= 4, () -> "Expected 4 or more tokens but found "
    + tokens.length);

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

private String encode(byte[] digest) {
  if (this.encodeHashAsBase64) {
    return Utf8.decode(Base64.getEncoder().encode(digest));
  }
  else {
    return new String(Hex.encode(digest));
  }
}

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

private byte[] decodePart(String part) {
  return Base64.getDecoder().decode(Utf8.encode(part));
}

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

@Override
  public AuditEvent getAuditEvent() {

    String name = getAuthentication().getName();

    try {
      // Store hash of name, to conceal accidental entry of sensitive info
      // (e.g. password)
      name = Utf8.decode(Base64.encode(MessageDigest.getInstance("SHA-1").digest(Utf8.encode(name))));
    } catch (NoSuchAlgorithmException shouldNeverHappen) {
      name = "NOSHA";
    }

    return createAuditRecord(name, AuditEventType.UserNotFound, getOrigin(getAuthenticationDetails()), "");

  }
}

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

private String encode(byte[] digest) {
  if (this.encodeHashAsBase64) {
    return Utf8.decode(Base64.getEncoder().encode(digest));
  }
  else {
    return new String(Hex.encode(digest));
  }
}

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

private String digest(CharSequence rawPassword, byte[] salt) {
  byte[] derived = SCrypt.generate(Utf8.encode(rawPassword), salt, cpuCost, memoryCost, parallelization, keyLength);
  String params = Long
      .toString(((int) (Math.log(cpuCost) / Math.log(2)) << 16L) | memoryCost << 8 | parallelization, 16);
  StringBuilder sb = new StringBuilder((salt.length + derived.length) * 2);
  sb.append("$").append(params).append('$');
  sb.append(encodePart(salt)).append('$');
  sb.append(encodePart(derived));
  return sb.toString();
}

相关文章