Example usage for org.apache.shiro.util SimpleByteSource SimpleByteSource

List of usage examples for org.apache.shiro.util SimpleByteSource SimpleByteSource

Introduction

In this page you can find the example usage for org.apache.shiro.util SimpleByteSource SimpleByteSource.

Prototype

public SimpleByteSource(InputStream stream) 

Source Link

Document

Creates an instance by converting the stream to a byte array.

Usage

From source file:annis.security.SerializableByteSource.java

License:Apache License

public SimpleByteSource getDelegate() {
    if (delegate == null) {
        delegate = new SimpleByteSource(bytes);
    }
    return delegate;
}

From source file:cn.powerdash.libsystem.common.security.authc.PrivateSaltPasswordService.java

License:Open Source License

public PrivateSaltPasswordService() {
    super();//from w w  w.  j a  v  a 2 s.c  o  m
    HashService hashService = getHashService();
    if (hashService instanceof DefaultHashService) {
        ((DefaultHashService) hashService).setPrivateSalt(new SimpleByteSource(PRIVATE_SALT));
    }
    DefaultHashService hashServiceInstance = new DefaultHashService();
    hashServiceInstance.setHashAlgorithmName("MD5");
    this.md5HashService = hashServiceInstance;
    hexHashFormat = new HexFormat();
    this.defaultHashService = super.getHashService();
    defaultHashFormat = super.getHashFormat();
}

From source file:com.app.shiro.UserSaltedAuthenticationInfo.java

License:Open Source License

@Override
public ByteSource getCredentialsSalt() {
    return new SimpleByteSource(Base64.decode(_salt));
}

From source file:com.masslink.idea.zigbee.shiro.UserPasswordService.java

License:Apache License

public UserPasswordService() {
    this.hashFormatWarned = false;
    DefaultHashService defaultHashService = new DefaultHashService();
    defaultHashService.setHashAlgorithmName(ALGORITHM);
    defaultHashService.setHashIterations(ITERATIONS);
    defaultHashService.setGeneratePublicSalt(true); //always want generated salts for user passwords to be most secure
    defaultHashService.setPrivateSalt(new SimpleByteSource(SALT));
    this.hashService = defaultHashService;
    this.hashFormat = new Shiro1CryptFormat();
    this.hashFormatFactory = new DefaultHashFormatFactory();
}

From source file:com.mycompany.shirofaces.SHA256.java

public static void main(String args[]) {
    RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    Object salt = rng.nextBytes();
    String hashedPasswordBase64 = new Sha256Hash("juancho18", salt, 1024).toBase64();

    Sha256Hash sha256Hash = new Sha256Hash("juancho18");
    System.out.println("Clave sin salt: " + sha256Hash.toHex());
    System.out.println("Clave con salt : " + hashedPasswordBase64);

    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashIterations(50000); // 500000
    hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
    hashService.setPrivateSalt(new SimpleByteSource("jumarome"));
    hashService.setGeneratePublicSalt(true);

    DefaultPasswordService passwordService = new DefaultPasswordService();
    passwordService.setHashService(hashService);
    String salte = hashService.getPrivateSalt().toBase64();
    String claveMaldita = passwordService.encryptPassword("unaep");
    System.out.println("Miraaa: " + claveMaldita);

    System.out.println("private salt= " + salte);

}

From source file:com.opass.security.SaltAwareJdbcRealm.java

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    //identify account to log to
    UsernamePasswordToken userPassToken = (UsernamePasswordToken) token;
    String username = userPassToken.getUsername();

    if (username == null) {
        log.debug("Username is null.");
        return null;
    }//from   w ww.  jav  a2  s  .com

    // read password hash and salt from db 
    PasswdSalt passwdSalt = getPasswordForUser(username);

    if (passwdSalt == null) {
        log.debug("No account found for user [" + username + "]");
        return null;
    }

    // return salted credentials
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(username, passwdSalt.password, getName());
    info.setCredentialsSalt(new SimpleByteSource(passwdSalt.salt));

    return info;
}

From source file:com.shiro.app.util.HashGenerator.java

License:Apache License

/**
 * Salt hash password.//from w  w  w  . j  a  va2 s .  com
 *
 * @param password the password
 * @param salt the salt
 * @return the string
 */
public String saltHashPassword(String password, String salt) {
    Sha256Hash hash = new Sha256Hash(password, (new SimpleByteSource(salt)).getBytes());
    return hash.toHex();
}

From source file:com.streamreduce.util.SecurityUtil.java

License:Apache License

/**
 * Returns a new encryption key/*from  w  w  w. j a va 2s.  co m*/
 *
 * @return encryption key in base64 encoding
 */
public static String generateNewKey() {
    AesCipherService cipherService = new AesCipherService();
    Key newKey = cipherService.generateNewKey();
    return new SimpleByteSource(newKey.getEncoded()).toBase64();
}

From source file:com.wegas.core.security.jparealm.JpaAccount.java

License:MIT License

/**
 *
 *//*from ww  w.  jav  a 2  s  .co m*/
@PreUpdate
public void preUpdate() {
    if (this.password != null && !this.password.isEmpty()) {
        this.passwordHex = new Sha256Hash(this.password, (new SimpleByteSource(this.getSalt())).getBytes())
                .toHex();
    }
}

From source file:com.wegas.core.security.jparealm.JpaRealm.java

License:MIT License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    try {//from  w  ww  . ja va2  s .  co m
        JpaAccount account = (JpaAccount) accountFacade().findByEmail(token.getUsername());
        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(account.getId(), account.getPasswordHex(),
                getName());
        info.setCredentialsSalt(new SimpleByteSource(account.getSalt()));
        return info;

    } catch (WegasNoResultException e) { // Could not find correponding mail, 
        try {
            JpaAccount account = (JpaAccount) accountFacade().findByUsername(token.getUsername());// try with the username
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(account.getId(),
                    account.getPasswordHex(), getName());
            info.setCredentialsSalt(new SimpleByteSource(account.getSalt()));
            return info;

        } catch (WegasNoResultException ex) {
            logger.error("Unable to find token", ex);
            return null;
        } catch (NamingException ex) {
            logger.error("Unable to find AccountFacade EJB", ex);
            return null;
        }
    } catch (NamingException ex) {
        logger.error("Unable to find AccountFacade EJB", ex);
        return null;
    }
}