本文整理了Java中org.springframework.security.crypto.codec.Hex
类的一些代码示例,展示了Hex
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex
类的具体详情如下:
包路径:org.springframework.security.crypto.codec.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));
}
内容来源于网络,如有侵权,请联系作者删除!