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

x33g5p2x  于2022-01-20 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(196)

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

Hex介绍

[英]Hex data encoder. Converts byte arrays (such as those obtained from message digests) into hexadecimal string representation.

For internal use only.
[中]十六进制数据编码器。将字节数组(如从消息摘要中获取的字节数组)转换为十六进制字符串表示形式。
仅供内部使用。

代码示例

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

/**
 * @return a pseduo random number (hex encoded)
 */
private String generatePseudoRandomNumber() {
  byte[] randomBytes = new byte[pseudoRandomNumberBytes];
  secureRandom.nextBytes(randomBytes);
  return new String(Hex.encode(randomBytes));
}

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

private byte[] decode(CharSequence encodedPassword) {
  return Hex.decode(encodedPassword);
}

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

@Test
public void migrate() {
  final int saltLength = KeyGenerators.secureRandom().getKeyLength();
  String encodedPassword = "ab1146a8458d4ce4e65789e5a3f60e423373cfa10b01abd23739e5ae2fdc37f8e9ede4ae6da65264";
  String originalEncodedPassword = "ab1146a8458d4ce4ab1146a8458d4ce4e65789e5a3f60e423373cfa10b01abd23739e5ae2fdc37f8e9ede4ae6da65264";
  byte[] originalBytes = Hex.decode(originalEncodedPassword);
  byte[] fixedBytes = Arrays.copyOfRange(originalBytes, saltLength,
      originalBytes.length);
  String fixedHex = String.valueOf(Hex.encode(fixedBytes));
  assertThat(fixedHex).isEqualTo(encodedPassword);
}

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

private String encode(byte[] bytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getEncoder().encodeToString(bytes);
  }
  return String.valueOf(Hex.encode(bytes));
}

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

private byte[] decode(CharSequence encodedPassword) {
  return Hex.decode(encodedPassword);
}

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

/**
 * @return a pseduo random number (hex encoded)
 */
private String generatePseudoRandomNumber() {
  byte[] randomBytes = new byte[pseudoRandomNumberBytes];
  secureRandom.nextBytes(randomBytes);
  return new String(Hex.encode(randomBytes));
}

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

private byte[] decode(String encodedBytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getDecoder().decode(encodedBytes);
  }
  return Hex.decode(encodedBytes);
}

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

private String encode(byte[] bytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getEncoder().encodeToString(bytes);
  }
  return String.valueOf(Hex.encode(bytes));
}

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

private byte[] decode(String encodedBytes) {
  if (this.encodeHashAsBase64) {
    return Base64.getDecoder().decode(encodedBytes);
  }
  return Hex.decode(encodedBytes);
}

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

public static String md5Hex(String data) {
    MessageDigest digest;
    try {
      digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException("No MD5 algorithm available!");
    }

    return new String(Hex.encode(digest.digest(data.getBytes())));
  }
}

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

public AesBytesEncryptor(String password, CharSequence salt,
    BytesKeyGenerator ivGenerator, CipherAlgorithm alg) {
  PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), Hex.decode(salt),
      1024, 256);
  SecretKey secretKey = newSecretKey("PBKDF2WithHmacSHA1", keySpec);
  this.secretKey = new SecretKeySpec(secretKey.getEncoded(), "AES");
  this.alg = alg;
  this.encryptor = alg.createCipher();
  this.decryptor = alg.createCipher();
  this.ivGenerator = ivGenerator != null ? ivGenerator : alg.defaultIvGenerator();
}

代码示例来源: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

public String decrypt(String encryptedText) {
  return Utf8.decode(encryptor.decrypt(Hex.decode(encryptedText)));
}

代码示例来源: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

public AesBytesEncryptor(String password, CharSequence salt,
    BytesKeyGenerator ivGenerator, CipherAlgorithm alg) {
  PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), Hex.decode(salt),
      1024, 256);
  SecretKey secretKey = newSecretKey("PBKDF2WithHmacSHA1", keySpec);
  this.secretKey = new SecretKeySpec(secretKey.getEncoded(), "AES");
  this.alg = alg;
  this.encryptor = alg.createCipher();
  this.decryptor = alg.createCipher();
  this.ivGenerator = ivGenerator != null ? ivGenerator : alg.defaultIvGenerator();
}

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

/**
 * Calculates the SHA digest and returns the value as a hex string.
 *
 * @param data Data to digest
 * @return SHA digest as a hex string
 */
public static String shaHex(String data) {
  return new String(Hex.encode(sha(data)));
}

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

public String decrypt(String encryptedText) {
  return Utf8.decode(encryptor.decrypt(Hex.decode(encryptedText)));
}

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

/**
 * Calculates the SHA digest and returns the value as a hex string.
 *
 * @param data Data to digest
 * @return SHA digest as a hex string
 */
public static String shaHex(byte[] data) {
  return new String(Hex.encode(sha(data)));
}

代码示例来源:origin: spring-cloud/spring-cloud-config

if (data.length() / 2 != (data.length() + 1) / 2) {
  try {
    Hex.decode(candidate);
    return candidate;

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

private String encode(CharSequence rawPassword, byte[] salt) {
  byte[] digest = digest(rawPassword, salt);
  return new String(Hex.encode(digest));
}

相关文章