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


Java DefaultHashService类代码示例

本文整理汇总了Java中org.apache.shiro.crypto.hash.DefaultHashService的典型用法代码示例。如果您正苦于以下问题:Java DefaultHashService类的具体用法?Java DefaultHashService怎么用?Java DefaultHashService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: genPassword

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
private String genPassword(final String psw, final String salt, final int iter) {
    try {

        final DefaultHashService hash = new DefaultHashService();
        hash.setPrivateSalt(ByteSource.Util.bytes(STATIC_SALT));
        hash.setHashIterations(iter);
        hash.setGeneratePublicSalt(false);
        hash.setHashAlgorithmName(ALG_NAME);

        final String pswEnc = hash.computeHash(new HashRequest.Builder()
                .setSource(psw).setSalt(salt).setIterations(iter).build()).toHex();

        return pswEnc;

    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:19,代码来源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java

示例2: activateService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
@Override
public void activateService()
    throws Exception
{
    configuration.refresh();
    PasswordRealmConfiguration config = configuration.get();
    String algorithm = config.hashAlgorithmName().get();
    Integer iterations = config.hashIterationsCount().get();
    if( algorithm != null || iterations != null )
    {
        DefaultHashService hashService = (DefaultHashService) passwordService.getHashService();
        if( algorithm != null )
        {
            hashService.setHashAlgorithmName( algorithm );
        }
        if( iterations != null )
        {
            hashService.setHashIterations( iterations );
        }
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:22,代码来源:PasswordRealmMixin.java

示例3: LegacyNexusPasswordService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
public LegacyNexusPasswordService() {
  //Initialize and configure sha1 password service
  this.sha1PasswordService = new DefaultPasswordService();
  DefaultHashService sha1HashService = new DefaultHashService();
  sha1HashService.setHashAlgorithmName("SHA-1");
  sha1HashService.setHashIterations(1);
  sha1HashService.setGeneratePublicSalt(false);
  this.sha1PasswordService.setHashService(sha1HashService);
  this.sha1PasswordService.setHashFormat(new HexFormat());

  //Initialize and configure md5 password service
  this.md5PasswordService = new DefaultPasswordService();
  DefaultHashService md5HashService = new DefaultHashService();
  md5HashService.setHashAlgorithmName("MD5");
  md5HashService.setHashIterations(1);
  md5HashService.setGeneratePublicSalt(false);
  this.md5PasswordService.setHashService(md5HashService);
  this.md5PasswordService.setHashFormat(new HexFormat());
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:20,代码来源:LegacyNexusPasswordService.java

示例4: main

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
public static void main(String[] args) throws NoSuchAlgorithmException {
    DefaultHashService hashService = new DefaultHashService(); // 默认算法SHA-512

    SecureRandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
    randomNumberGenerator.setSeed("123".getBytes());
    String salt = randomNumberGenerator.nextBytes().toHex();

    HashRequest request = new HashRequest.Builder().setAlgorithmName("MD5")
            .setSource(ByteSource.Util.bytes("123456")).setSalt(ByteSource.Util.bytes(salt)).setIterations(2)
            .build();
    String hex = hashService.computeHash(request).toHex();
    System.out.println(salt);
    System.out.println(hex);
    KeyGenerator keygen = KeyGenerator.getInstance("AES");
    SecretKey deskey = keygen.generateKey();
    System.out.println(Base64.encodeToString(deskey.getEncoded()));
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:18,代码来源:PasswordAndKeyGenerator.java

示例5: calculateHash

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
private static Hash calculateHash(String password) {
    ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
    DefaultHashService hashService = new DefaultHashService();
    hashService.setPrivateSalt(privateSalt);
    hashService.setGeneratePublicSalt(true);
    hashService.setHashIterations(ITERATIONS);

    HashRequest.Builder builder = new HashRequest.Builder();
    builder.setSource(ByteSource.Util.bytes(password));

    Hash hash = hashService.computeHash(builder.build());

    log.info("Hash algorithm {}, iterations {}, public salt {}", hash.getAlgorithmName(), hash.getIterations(), hash.getSalt());

    return hash;
}
 
开发者ID:dschadow,项目名称:JavaSecurity,代码行数:17,代码来源:SHA512.java

示例6: verifyPassword

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
private static boolean verifyPassword(byte[] originalHash, ByteSource publicSalt, String password) {
    ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
    DefaultHashService hashService = new DefaultHashService();
    hashService.setPrivateSalt(privateSalt);
    hashService.setHashIterations(ITERATIONS);

    HashRequest.Builder builder = new HashRequest.Builder();
    builder.setSource(ByteSource.Util.bytes(password));
    builder.setSalt(publicSalt);

    Hash comparisonHash = hashService.computeHash(builder.build());

    log.info("password: {}", password);
    log.info("1 hash: {}", Hex.encodeToString(originalHash));
    log.info("2 hash: {}", comparisonHash.toHex());

    return Arrays.equals(originalHash, comparisonHash.getBytes());
}
 
开发者ID:dschadow,项目名称:JavaSecurity,代码行数:19,代码来源:SHA512.java

示例7: digestEncodedPassword

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
/**
 * Digest encoded password.
 *
 * @param encodedPassword the encoded password
 * @param values the values retrieved from database
 * @return the digested password
 */
protected String digestEncodedPassword(final String encodedPassword, final Map<String, Object> values) {
    final ConfigurableHashService hashService = new DefaultHashService();

    if (StringUtils.isNotBlank(this.staticSalt)) {
        hashService.setPrivateSalt(ByteSource.Util.bytes(this.staticSalt));
    }
    hashService.setHashAlgorithmName(this.algorithmName);

    Long numOfIterations = this.numberOfIterations;
    if (values.containsKey(this.numberOfIterationsFieldName)) {
        final String longAsStr = values.get(this.numberOfIterationsFieldName).toString();
        numOfIterations = Long.valueOf(longAsStr);
    }

    hashService.setHashIterations(numOfIterations.intValue());
    if (!values.containsKey(this.saltFieldName)) {
        throw new RuntimeException("Specified field name for salt does not exist in the results");
    }

    final String dynaSalt = values.get(this.saltFieldName).toString();
    final HashRequest request = new HashRequest.Builder()
                                .setSalt(dynaSalt)
                                .setSource(encodedPassword)
                                .build();
    return hashService.computeHash(request).toHex();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:34,代码来源:QueryAndEncodeDatabaseAuthenticationHandler.java

示例8: digestEncodedPassword

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
/**
 * Digest encoded password.
 *
 * @param encodedPassword the encoded password
 * @param values          the values retrieved from database
 * @return the digested password
 */
protected String digestEncodedPassword(final String encodedPassword, final Map<String, Object> values) {
    final ConfigurableHashService hashService = new DefaultHashService();

    if (StringUtils.isNotBlank(this.staticSalt)) {
        hashService.setPrivateSalt(ByteSource.Util.bytes(this.staticSalt));
    }
    hashService.setHashAlgorithmName(this.algorithmName);

    Long numOfIterations = this.numberOfIterations;
    if (values.containsKey(this.numberOfIterationsFieldName)) {
        final String longAsStr = values.get(this.numberOfIterationsFieldName).toString();
        numOfIterations = Long.valueOf(longAsStr);
    }

    hashService.setHashIterations(numOfIterations.intValue());
    if (!values.containsKey(this.saltFieldName)) {
        throw new RuntimeException("Specified field name for salt does not exist in the results");
    }

    final String dynaSalt = values.get(this.saltFieldName).toString();
    final HashRequest request = new HashRequest.Builder()
            .setSalt(dynaSalt)
            .setSource(encodedPassword)
            .build();
    return hashService.computeHash(request).toHex();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:34,代码来源:QueryAndEncodeDatabaseAuthenticationHandler.java

示例9: genPassword

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
private static String genPassword(final String psw, final String salt, final int iter) {
    try {
        final DefaultHashService hash = new DefaultHashService();
        hash.setPrivateSalt(ByteSource.Util.bytes(STATIC_SALT));
        hash.setHashIterations(iter);
        hash.setGeneratePublicSalt(false);
        hash.setHashAlgorithmName(ALG_NAME);

        return hash.computeHash(new HashRequest.Builder().setSource(psw).setSalt(salt).setIterations(iter).build()).toHex();
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:14,代码来源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java

示例10: test

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
@Test
    public void test() throws Exception {
        ConfigurableHashService hashService = new DefaultHashService();
        hashService.setPrivateSalt(ByteSource.Util.bytes(this.staticSalt));
        hashService.setHashAlgorithmName(this.algorithmName);
        hashService.setHashIterations(2);
        HashRequest request = new HashRequest.Builder()
                .setSalt(dynaSalt)
                .setSource(encodedPassword)
                .build();
        String res =  hashService.computeHash(request).toHex();
//        System.out.println(res);
        Assert.assertEquals("bfb194d5bd84a5fc77c1d303aefd36c3", res);
    }
 
开发者ID:kawhii,项目名称:sso,代码行数:15,代码来源:PasswordSaltTest.java

示例11: passwordService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public PasswordService passwordService() {
    DefaultPasswordService service = new DefaultPasswordService();

    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashAlgorithmName(shiroProperties.getHashAlgorithmName());
    hashService.setHashIterations(shiroProperties.getHashIterations());
    service.setHashService(hashService);

    return service;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:13,代码来源:ShiroAutoConfiguration.java

示例12: DefaultPasswordService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
public DefaultPasswordService() {
    this.hashFormatWarned = false;

    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashAlgorithmName(DEFAULT_HASH_ALGORITHM);
    hashService.setHashIterations(DEFAULT_HASH_ITERATIONS);
    hashService.setGeneratePublicSalt(true); //always want generated salts for user passwords to be most secure
    this.hashService = hashService;

    this.hashFormat = new Shiro1CryptFormat();
    this.hashFormatFactory = new DefaultHashFormatFactory();
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:13,代码来源:DefaultPasswordService.java

示例13: DefaultSecurityPasswordService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
@Inject
public DefaultSecurityPasswordService(@Named("legacy") final PasswordService legacyPasswordService) {
  this.passwordService = new DefaultPasswordService();
  this.legacyPasswordService = checkNotNull(legacyPasswordService);

  //Create and set a hash service according to our hashing policies
  DefaultHashService hashService = new DefaultHashService();
  hashService.setHashAlgorithmName(DEFAULT_HASH_ALGORITHM);
  hashService.setHashIterations(DEFAULT_HASH_ITERATIONS);
  hashService.setGeneratePublicSalt(true);
  this.passwordService.setHashService(hashService);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:13,代码来源:DefaultSecurityPasswordService.java

示例14: createPasswordService

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
/**
 * Creates the password service without registering it.
 * 
 * @param repo  the component repository, only used to register secondary items like lifecycle, not null
 * @return the password service, not null
 */
protected PasswordService createPasswordService(ComponentRepository repo) {
  DefaultHashService hashService = new DefaultHashService();
  hashService.setHashAlgorithmName(getHashAlgorithm());
  hashService.setHashIterations(getHashIterations());
  hashService.setGeneratePublicSalt(true);
  hashService.setPrivateSalt(new SimpleByteSource(getPrivateSalt()));
  DefaultPasswordService pwService = new DefaultPasswordService();
  pwService.setHashService(hashService);
  return pwService;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:ShiroSecurityComponentFactory.java

示例15: encryptPasswordAndGenSalt

import org.apache.shiro.crypto.hash.DefaultHashService; //导入依赖的package包/类
private void encryptPasswordAndGenSalt(User user) {
    SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
    generator.setSeed(SEED.getBytes());
    String salt = generator.nextBytes().toHex();
    user.setSalt(salt);

    DefaultHashService hashService = new DefaultHashService();
    HashRequest request = new HashRequest.Builder().setAlgorithmName(algorithmName)
            .setSource(ByteSource.Util.bytes(user.getPassword())).setSalt(ByteSource.Util.bytes(salt))
            .setIterations(hashIterations).build();
    user.setPassword(hashService.computeHash(request).toHex());
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:13,代码来源:UserService.java


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