本文整理汇总了Java中org.springframework.security.crypto.codec.Hex类的典型用法代码示例。如果您正苦于以下问题:Java Hex类的具体用法?Java Hex怎么用?Java Hex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Hex类属于org.springframework.security.crypto.codec包,在下文中一共展示了Hex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPassword
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public void setPassword (String password)
{
// Encrypt password with MessageDigest
PasswordEncryption encryption = PasswordEncryption.MD5;
setPasswordEncryption (encryption);
if (encryption != PasswordEncryption.NONE) // when configurable
{
try
{
MessageDigest md =
MessageDigest.getInstance (encryption.getAlgorithmKey ());
password =
new String (
Hex.encode (md.digest (password.getBytes ("UTF-8"))));
}
catch (Exception e)
{
throw new UserBadEncryptionException (
"There was an error while encrypting password of user " +
getUsername (), e);
}
}
this.password = password;
}
示例2: encrypt
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public static String encrypt (String password, PasswordEncryption encryption)
throws EncryptPasswordException
{
if (encryption != PasswordEncryption.NONE) // when configurable
{
try
{
MessageDigest md =
MessageDigest.getInstance (encryption.getAlgorithmKey ());
password =
new String (
Hex.encode (md.digest (password.getBytes ("UTF-8"))));
}
catch (Exception e)
{
throw new EncryptPasswordException (
"There was an error while encrypting password.", e);
}
}
return password;
}
示例3: computeSignature
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
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())));
}
示例4: getSalt
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
/**
* Additional method to get salt from object.
*
* @param obj entity object
* @return string with salt
*/
private static CharSequence getSalt(Object obj) throws IllegalAccessException {
CharSequence salt;
try {
Field saltField = obj.getClass().getDeclaredField("salt");
saltField.setAccessible(true);
salt = (CharSequence) saltField.get(obj);
if (salt == null || salt.toString().isEmpty()) {
salt = KeyGenerators.string().generateKey();
saltField.set(obj, salt);
}
saltField.setAccessible(false);
} catch (NoSuchFieldException e) {
LOGGER.info("Decrypt exception: salt field not found.");
// Use encoded class name as salt, if salt field not available.
salt = new String(Hex.encode(obj.getClass().getName().getBytes()));
}
return salt;
}
示例5: check
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
@SneakyThrows
public boolean check(String gitHubSignature, String body) {
if(gitHubSignature == null || !gitHubSignature.startsWith(SIGNATURE_PREFIX)) {
return false;
}
AccessToken expectedToken = accessTokens.findOne(AccessToken.CLA_ACCESS_TOKEN_ID);
if(expectedToken == null) {
return false;
}
String providedHmac = gitHubSignature.substring(SIGNATURE_PREFIX.length());
byte[] providedHmacBytes = Hex.decode(providedHmac);
byte[] expectedBytes = sign(body, expectedToken.getToken());
return MessageDigest.isEqual(providedHmacBytes, expectedBytes);
}
示例6: genKey
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
private static Key genKey() throws Exception {
synchronized (Crypto.class) {
if (encKey == null) {
byte[] salt = AppConfig.getInstance().getSalt().getBytes(CHARSET);
String cipherSeed = AppConfig.getInstance().getCipherSeed();
MessageDigest md = MessageDigest.getInstance(MD_ALGO);
char[] password = Hex.encode(md.digest(cipherSeed.getBytes(CHARSET)));
PBEKeySpec encPBESpec = new PBEKeySpec(password, salt, ITERATION_COUNT, KEN_LEN);
SecretKeyFactory encKeyFact = SecretKeyFactory.getInstance(TMPKEY_ALGO);
Key tmpKey = encKeyFact.generateSecret(encPBESpec);
encKey = new SecretKeySpec(tmpKey.getEncoded(), KEY_ALGO);
}
}
return encKey;
}
示例7: computeSignature
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public String computeSignature(String details, long expires) {
StringBuilder signatureBuilder = new StringBuilder();
signatureBuilder.append(details).append(SEPARATOR);
signatureBuilder.append(expires).append(SEPARATOR);
signatureBuilder.append(secretKey);
//TODO: Use javax.crypto.Mac instead of MD5
// https://github.com/Robbert1/boot-stateless-auth/blob/master/src/main/java/com/jdriven/stateless/security/TokenHandler.java
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())));
}
示例8: computeSignature
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
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())));
}
示例9: computeSignature
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public static String computeSignature(UserDetails user, long expires)
{
StringBuilder signatureBuilder = new StringBuilder();
signatureBuilder.append(user.getUsername());
signatureBuilder.append(":");
signatureBuilder.append(expires);
signatureBuilder.append(":");
signatureBuilder.append(user.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())));
}
示例10: computeSignature
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
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())));
}
示例11: getChecksum
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public String getChecksum() {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.update(Boolean.toString(fixPrice).getBytes());
digest.update(Integer.toString(ordinal).getBytes());
digest.update(Integer.toString(availableQuantity).getBytes());
digest.update(Integer.toString(maxQtyPerOrder).getBytes());
digest.update(utcInception.toString().getBytes());
digest.update(utcExpiration.toString().getBytes());
digest.update(Optional.ofNullable(vat).map(BigDecimal::toString).orElse("").getBytes());
digest.update(vatType.name().getBytes());
digest.update(type.name().getBytes());
if (supplementPolicy != null) {
digest.update(supplementPolicy.name().getBytes());
}
return new String(Hex.encode(digest.digest()));
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
示例12: toSha1
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public static String toSha1(String value) {
if (value == null) {
return null;
}
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
md.update(value.getBytes(StandardCharsets.UTF_8));
char[] array = Hex.encode(md.digest());
return new String(array);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
示例13: changeRootPassword
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
@PreAuthorize ("hasRole('ROLE_SYSTEM_MANAGER')")
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
@Caching (evict = {
@CacheEvict (value = "user", allEntries = true),
@CacheEvict (value = "userByName", allEntries = true)})
public void changeRootPassword (String new_pwd, String old_pwd)
{
User root =
userDao.getByName (
cfgManager.getAdministratorConfiguration ().getName ());
PasswordEncryption encryption = root.getPasswordEncryption ();
if (encryption != PasswordEncryption.NONE)
{
try
{
MessageDigest md = MessageDigest.getInstance(
encryption.getAlgorithmKey());
old_pwd = new String(
Hex.encode(md.digest(old_pwd.getBytes("UTF-8"))));
}
catch (Exception e)
{
throw new UserBadEncryptionException (
"There was an error while encrypting password of root user",
e);
}
}
if ( (old_pwd == null) || ("".equals (old_pwd)) ||
( !root.getPassword ().equals (old_pwd)))
throw new SecurityException ("Wrong password.");
if ( (new_pwd == null) || "".equals (new_pwd.trim ()))
throw new SecurityException ("New password cannot be empty.");
String password = new_pwd.trim ();
root.setPassword (password);
userDao.update (root);
}
示例14: getGeneratedValue
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
/**
* @param base32Key base32 encoded key
* @param timeStepInMills
* @return
*/
public static String getGeneratedValue(String base32Key, long timeStepInMills) {
// time step
String hexKey = new String(Hex.encode(new Base32().decode(base32Key)));
return TOTP.generateTOTP(hexKey,
Long.toHexString(System.currentTimeMillis() / timeStepInMills),
"6",
"HmacSHA1");
}
示例15: generateHexIdentity
import org.springframework.security.crypto.codec.Hex; //导入依赖的package包/类
public static String generateHexIdentity(String value) {
try {
if (md5MessageDigest != null) {
return new String(Hex.encode(md5MessageDigest.digest(value.getBytes("utf-8"))));
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return value;
}