本文整理了Java中org.springframework.security.crypto.codec.Hex.encode()
方法的一些代码示例,展示了Hex.encode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex.encode()
方法的具体详情如下:
包路径:org.springframework.security.crypto.codec.Hex
类名称:Hex
方法名:encode
暂无
代码示例来源: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 String encode(byte[] bytes) {
if (this.encodeHashAsBase64) {
return Base64.getEncoder().encodeToString(bytes);
}
return String.valueOf(Hex.encode(bytes));
}
代码示例来源: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-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 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
/**
* 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: spring-projects/spring-security
private String encode(CharSequence rawPassword, byte[] salt) {
byte[] digest = digest(rawPassword, salt);
return new String(Hex.encode(digest));
}
代码示例来源:origin: spring-projects/spring-security
public String generateKey() {
return new String(Hex.encode(keyGenerator.generateKey()));
}
代码示例来源:origin: weibocom/motan
public static String computeSignature(UserDetails userDetails, long expires) {
StringBuilder signatureBuilder = new StringBuilder();
signatureBuilder.append(userDetails.getUsername());
signatureBuilder.append(":");
signatureBuilder.append(expires);
signatureBuilder.append(":");
signatureBuilder.append(userDetails.getPassword());
signatureBuilder.append(":");
signatureBuilder.append(TokenUtils.MAGIC_KEY);
MessageDigest digest;
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("No MD5 algorithm available!");
}
return new String(Hex.encode(digest.digest(signatureBuilder.toString().getBytes())));
}
代码示例来源:origin: spring-projects/spring-security
@Override
public String encode(CharSequence rawPassword) {
byte[] salt = this.saltGenerator.generateKey();
byte[] encoded = encodeAndConcatenate(rawPassword, salt);
return String.valueOf(Hex.encode(encoded));
}
代码示例来源:origin: spring-projects/spring-security
public String encrypt(String text) {
return new String(Hex.encode(encryptor.encrypt(Utf8.encode(text))));
}
代码示例来源:origin: spring-projects/spring-security
@Before
public void setup() {
// generate random password, salt, and test data
password = UUID.randomUUID().toString();
byte[] saltBytes = new byte[16];
secureRandom.nextBytes(saltBytes);
salt = new String(Hex.encode(saltBytes));
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void hexEncode() {
byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
(byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
String result = new String(Hex.encode(bytes));
assertThat(result).isEqualTo("01ff414243c0c1c2");
}
代码示例来源:origin: spring-projects/spring-security
@Before
public void setup() {
// generate random password, salt, and test data
SecureRandom secureRandom = new SecureRandom();
password = UUID.randomUUID().toString();
byte[] saltBytes = new byte[16];
secureRandom.nextBytes(saltBytes);
salt = new String(Hex.encode(saltBytes));
testData = new byte[1024 * 1024];
secureRandom.nextBytes(testData);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void encode() {
assertThat(Hex.encode(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
(byte) 'D' })).isEqualTo(new char[] {'4', '1', '4', '2', '4', '3', '4', '4'});
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void encodeEmptyByteArray() {
assertThat(Hex.encode(new byte[] {})).isEmpty();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void roundtripWhenUsingDefaultCipherThenEncryptsAndDecrypts() {
CryptoAssumptions.assumeCBCJCE();
AesBytesEncryptor encryptor = new AesBytesEncryptor(this.password, this.hexSalt, this.generator);
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
assertThat(new String(Hex.encode(encryption)))
.isEqualTo("4b0febebd439db7ca77153cb254520c3b7232ac29355d07869433f1ecf55fe94");
byte[] decryption = encryptor.decrypt(encryption);
assertThat(new String(decryption)).isEqualTo(this.secret);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void roundtripWhenUsingGcmThenEncryptsAndDecrypts() {
CryptoAssumptions.assumeGCMJCE();
AesBytesEncryptor encryptor = new AesBytesEncryptor(this.password, this.hexSalt, this.generator, GCM);
byte[] encryption = encryptor.encrypt(this.secret.getBytes());
assertThat(new String(Hex.encode(encryption)))
.isEqualTo("4b0febebd439db7ca77153cb254520c3e4d61ae38207b4e42b820d311dc3d4e0e2f37ed5ee");
byte[] decryption = encryptor.decrypt(encryption);
assertThat(new String(decryption)).isEqualTo(this.secret);
}
代码示例来源: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
@Test
public void digestIsCorrectFor3Iterations() {
Digester digester = new Digester("SHA-1", 3);
byte[] result = digester.digest(Utf8.encode("text"));
// echo -n text | openssl sha1 -binary | openssl sha1 -binary | openssl sha1
assertThat(new String(Hex.encode(result))).isEqualTo("3cfa28da425eca5b894f0af2b158adf7001e000f");
}
内容来源于网络,如有侵权,请联系作者删除!