当前位置: 首页>>代码示例>>Java>>正文


Java Hex.encode方法代码示例

本文整理汇总了Java中org.springframework.security.crypto.codec.Hex.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Hex.encode方法的具体用法?Java Hex.encode怎么用?Java Hex.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.crypto.codec.Hex的用法示例。


在下文中一共展示了Hex.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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())));
}
 
开发者ID:aboieriu,项目名称:token-based-rest-auth,代码行数:21,代码来源:TokenUtils.java

示例2: 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;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:25,代码来源:User.java

示例3: 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;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:22,代码来源:EncryptPassword.java

示例4: 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())));
}
 
开发者ID:edu-xored,项目名称:memorise,代码行数:20,代码来源:TokenUtils.java

示例5: 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;
}
 
开发者ID:bulktrade,项目名称:SMSC,代码行数:29,代码来源:EncrypterUtil.java

示例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;
    }
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:22,代码来源:Crypto.java

示例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())));
}
 
开发者ID:javicacheiro,项目名称:hadoop-on-demand-rest-jhipster,代码行数:17,代码来源:TokenProvider.java

示例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())));
}
 
开发者ID:davidsan,项目名称:montgomery,代码行数:21,代码来源:TokenUtils.java

示例9: 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())));
}
 
开发者ID:arkenoid,项目名称:jersey-angular,代码行数:21,代码来源:TokenUtils.java

示例10: 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);
    }
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:21,代码来源:AdditionalService.java

示例11: 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);
    }
}
 
开发者ID:Evolveum,项目名称:gizmo-v3,代码行数:17,代码来源:GizmoUtils.java

示例12: md5Hex

import org.springframework.security.crypto.codec.Hex; //导入方法依赖的package包/类
public static String md5Hex(String data) {
    try {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        return new String(Hex.encode(digest.digest(data.getBytes())));
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("No MD5 algorithm available!");
    }

}
 
开发者ID:jestevez,项目名称:autenticacion-as400-spring-security,代码行数:10,代码来源:CustomAuthenticationProvider.java

示例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);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:39,代码来源:SystemService.java

示例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");
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:14,代码来源:TOTPUtils.java

示例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;
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:11,代码来源:SecurityUtils.java


注:本文中的org.springframework.security.crypto.codec.Hex.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。