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


Java HashRequest类代码示例

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


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

示例1: genPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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: passwordsMatch

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
public boolean passwordsMatch(Object plaintext, Hash saved) {
    ByteSource plaintextBytes = createByteSource(plaintext);

    if (saved == null || saved.isEmpty()) {
        return plaintextBytes == null || plaintextBytes.isEmpty();
    } else {
        if (plaintextBytes == null || plaintextBytes.isEmpty()) {
            return false;
        }
    }

    HashRequest request = buildHashRequest(plaintextBytes, saved);

    Hash computed = this.hashService.computeHash(request);

    return saved.equals(computed);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:DefaultPasswordService.java

示例3: main

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例4: calculateHash

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例5: verifyPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例6: digestEncodedPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例7: digestEncodedPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例8: genPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例9: test

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例10: hashPassword

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
public Hash hashPassword(Object plaintext) {
    ByteSource plaintextBytes = createByteSource(plaintext);
    if (plaintextBytes == null || plaintextBytes.isEmpty()) {
        return null;
    }
    HashRequest request = createHashRequest(plaintextBytes);
    return hashService.computeHash(request);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:9,代码来源:DefaultPasswordService.java

示例11: buildHashRequest

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
protected HashRequest buildHashRequest(ByteSource plaintext, Hash saved) {
    //keep everything from the saved hash except for the source:
    return new HashRequest.Builder().setSource(plaintext)
            //now use the existing saved data:
            .setAlgorithmName(saved.getAlgorithmName())
            .setSalt(saved.getSalt())
            .setIterations(saved.getIterations())
            .build();
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:10,代码来源:DefaultPasswordService.java

示例12: encryptPasswordAndGenSalt

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的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

示例13: passwordsMatch

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
public boolean passwordsMatch(User user, String password) {
    SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
    generator.setSeed(SEED.getBytes());
    String salt = user.getSalt();

    DefaultHashService hashService = new DefaultHashService();
    HashRequest request = new HashRequest.Builder().setAlgorithmName(algorithmName)
            .setSource(ByteSource.Util.bytes(password)).setSalt(ByteSource.Util.bytes(salt))
            .setIterations(hashIterations).build();

    return user.getPassword().equals(hashService.computeHash(request).toHex());
}
 
开发者ID:howiefh,项目名称:jee-restful-web,代码行数:13,代码来源:UserService.java

示例14: computeHash

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
@Override
public Hash computeHash(HashRequest request) {
    SimpleHash result = new SimpleHash(request.getAlgorithmName());
    result.setSalt(request.getSalt());
    result.setIterations(request.getIterations());
    result.setBytes(request.getSource().getBytes());
    return result;
}
 
开发者ID:ManyDesigns,项目名称:Portofino,代码行数:9,代码来源:PlaintextHashService.java

示例15: createAuthenticationInfo

import org.apache.shiro.crypto.hash.HashRequest; //导入依赖的package包/类
@Override
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, 
      Object ldapPrincipal,
      Object ldapCredentials, LdapContext ldapContext) throws NamingException {
  HashRequest.Builder builder = new HashRequest.Builder();
  Hash credentialsHash = hashService
        .computeHash(builder.setSource(token.getCredentials())
              .setAlgorithmName(HASHING_ALGORITHM).build());
  return new SimpleAuthenticationInfo(token.getPrincipal(), 
        credentialsHash.toHex(), credentialsHash.getSalt(),
        getName());
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:13,代码来源:LdapRealm.java


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