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


Java Hash类代码示例

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


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

示例1: calculateHash

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

示例2: format

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
public String format(Hash hash) {
    if (hash == null) {
        return null;
    }

    String algorithmName = hash.getAlgorithmName();
    ByteSource salt = hash.getSalt();
    int iterations = hash.getIterations();
    StringBuilder sb = new StringBuilder(MCF_PREFIX).append(algorithmName).append(TOKEN_DELIMITER).append(iterations).append(TOKEN_DELIMITER);

    if (salt != null) {
        sb.append(salt.toBase64());
    }

    sb.append(TOKEN_DELIMITER);
    sb.append(hash.toBase64());

    return sb.toString();
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:20,代码来源:Shiro1CryptFormat.java

示例3: passwordsMatch

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

示例4: doCredentialsMatch

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {

        PasswordService service = ensurePasswordService();

        Object submittedPassword = getSubmittedPassword(token);
        Object storedCredentials = getStoredPassword(info);
        assertStoredCredentialsType(storedCredentials);

        if (storedCredentials instanceof Hash) {
            Hash hashedPassword = (Hash)storedCredentials;
            HashingPasswordService hashingService = assertHashingPasswordService(service);
            return hashingService.passwordsMatch(submittedPassword, hashedPassword);
        }
        //otherwise they are a String (asserted in the 'assertStoredCredentialsType' method call above):
        String formatted = (String)storedCredentials;
        return passwordService.passwordsMatch(submittedPassword, formatted);
    }
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:PasswordMatcher.java

示例5: doGetAuthenticationInfo

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	if (token instanceof UsernamePasswordToken) {
		final UsernamePasswordToken upToken = (UsernamePasswordToken)token;
		final String username = upToken.getUsername();

		final UserStorage storage = UsersPlugin.getInstance().getStorage();
		final DB db = storage.getTxMaker().makeTx();
		try {
			final User user = storage.getUserMap(db).get(username);
			if (user == null) {
				return null;
			}
			Hash hash = new Shiro1CryptFormat().parse(user.getHashedPassword());
			return new UserInfo(user.getUsername(), hash);
		} finally {
			db.close();
		}
	}
	return null;
}
 
开发者ID:mondo-project,项目名称:mondo-integration,代码行数:22,代码来源:UsersRealm.java

示例6: verifyPassword

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

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

示例8: buildHashRequest

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

示例9: assertStoredCredentialsType

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
private void assertStoredCredentialsType(Object credentials) {
    if (credentials instanceof String || credentials instanceof Hash) {
        return;
    }

    String msg = "Stored account credentials are expected to be either a " +
            Hash.class.getName() + " instance or a formatted hash String.";
    throw new IllegalArgumentException(msg);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:10,代码来源:PasswordMatcher.java

示例10: testHash

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
@Test
public void testHash() {
  String password = "testpassword";
  Hash hash = underTest.hashPassword(password);

  assertThat(underTest.passwordsMatch(password, hash), is(true));
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:8,代码来源:DefaultSecurityPasswordServiceTest.java

示例11: computeHash

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

示例12: createAuthenticationInfo

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

示例13: setPassword

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
public void setPassword(ByteSource password, long minstolive) {
    timeout = System.currentTimeMillis() + minstolive * 60 * 1000;
    HashRequest request = new HashRequest.Builder()
        .setSource(password)
        .setSalt( getSalt() )
        .build();
    Hash hash = realm.getHashService().computeHash(request);
    this.password = hash.toHex();
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:10,代码来源:BaseUserStore.java

示例14: main

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
public static void main(String[] args) {
    String password = "SHA-512 hash sample text";

    Hash hash = calculateHash(password);
    boolean correct = verifyPassword(hash.getBytes(), hash.getSalt(), password);

    log.info("Entered password is correct: {}", correct);
}
 
开发者ID:dschadow,项目名称:JavaSecurity,代码行数:9,代码来源:SHA512.java

示例15: getCredentialsSalt

import org.apache.shiro.crypto.hash.Hash; //导入依赖的package包/类
@Transient
@Override
public ByteSource getCredentialsSalt() {
    return Hash.Util.bytes(passwordSalt);
}
 
开发者ID:xiaolongzuo,项目名称:niubi-job,代码行数:6,代码来源:User.java


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