本文整理了Java中org.apache.shiro.crypto.hash.Hash.getSalt()
方法的一些代码示例,展示了Hash.getSalt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash.getSalt()
方法的具体详情如下:
包路径:org.apache.shiro.crypto.hash.Hash
类名称:Hash
方法名:getSalt
[英]Returns a salt used to compute the hash or null if no salt was used.
[中]返回用于计算哈希的salt,如果未使用salt,则返回null。
代码示例来源:origin: apache/shiro
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();
}
代码示例来源:origin: apache/shiro
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();
}
代码示例来源:origin: magefree/mage
public AuthorizedUser(String name, Hash hash, String email) {
this.name = name;
this.password = hash.toBase64();
this.salt = hash.getSalt().toBase64();
this.hashAlgorithm = hash.getAlgorithmName();
this.hashIterations = hash.getIterations();
this.email = email;
this.chatLockedUntil = null;
this.active = true;
this.lockedUntil = null;
}
代码示例来源:origin: org.apache.shiro/shiro-core
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();
}
代码示例来源:origin: org.apache.shiro/shiro-crypto-hash
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();
}
代码示例来源:origin: dschadow/JavaSecurity
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);
}
代码示例来源:origin: Waffle/waffle
/**
* Builds the authentication info.
*
* @param token
* the token
* @param principal
* the principal
* @return the authentication info
*/
private AuthenticationInfo buildAuthenticationInfo(final UsernamePasswordToken token, final Object principal) {
AuthenticationInfo authenticationInfo;
final HashingPasswordService hashService = this.getHashService();
if (hashService != null) {
final Hash hash = hashService.hashPassword(token.getPassword());
final ByteSource salt = hash.getSalt();
authenticationInfo = new SimpleAuthenticationInfo(principal, hash, salt, AbstractWaffleRealm.REALM_NAME);
} else {
final Object creds = token.getCredentials();
authenticationInfo = new SimpleAuthenticationInfo(principal, creds, AbstractWaffleRealm.REALM_NAME);
}
return authenticationInfo;
}
代码示例来源:origin: com.github.waffle/waffle-shiro
/**
* Builds the authentication info.
*
* @param token
* the token
* @param principal
* the principal
* @return the authentication info
*/
private AuthenticationInfo buildAuthenticationInfo(final UsernamePasswordToken token, final Object principal) {
AuthenticationInfo authenticationInfo;
final HashingPasswordService hashService = this.getHashService();
if (hashService != null) {
final Hash hash = hashService.hashPassword(token.getPassword());
final ByteSource salt = hash.getSalt();
authenticationInfo = new SimpleAuthenticationInfo(principal, hash, salt, AbstractWaffleRealm.REALM_NAME);
} else {
final Object creds = token.getCredentials();
authenticationInfo = new SimpleAuthenticationInfo(principal, creds, AbstractWaffleRealm.REALM_NAME);
}
return authenticationInfo;
}
代码示例来源:origin: dschadow/JavaSecurity
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;
}
代码示例来源:origin: org.apache.knox/gateway-provider-security-shiro
@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());
}
代码示例来源:origin: apache/knox
@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());
}
代码示例来源:origin: org.apache.knox/gateway-provider-security-shiro
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
UnixUser user = null;
try {
user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
} catch (PAMException e) {
handleAuthFailure(token, e.getMessage(), e);
}
HashRequest.Builder builder = new HashRequest.Builder();
Hash credentialsHash = hashService
.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
/* Coverity Scan CID 1361684 */
if (credentialsHash == null) {
handleAuthFailure(token, "Failed to compute hash", null);
}
return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(),
getName());
}
代码示例来源:origin: apache/knox
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
UnixUser user = null;
try {
user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
} catch (PAMException e) {
handleAuthFailure(token, e.getMessage(), e);
}
HashRequest.Builder builder = new HashRequest.Builder();
Hash credentialsHash = hashService
.computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
/* Coverity Scan CID 1361684 */
if (credentialsHash == null) {
handleAuthFailure(token, "Failed to compute hash", null);
}
return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(),
getName());
}
内容来源于网络,如有侵权,请联系作者删除!