Tabnine Logo
Utf8
Code IndexAdd Tabnine to your IDE (free)

How to use
Utf8
in
org.springframework.security.crypto.codec

Best Java code snippets using org.springframework.security.crypto.codec.Utf8 (Showing top 20 results out of 315)

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();
}
org.springframework.security.crypto.codecUtf8

Javadoc

UTF-8 Charset encoder/decoder.

For internal use only.

Most used methods

  • encode
    Get the bytes of the String in UTF-8 encoded form.
  • decode
    Decode the bytes in UTF-8 form into a String.

Popular in Java

  • Reading from database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • scheduleAtFixedRate (Timer)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now