Package org.apache.shiro.crypto

Examples of org.apache.shiro.crypto.SecureRandomNumberGenerator


    public void testGeneratePassword() {
        String algorithmName = "md5";
        String username = "liu";
        String password = "123";
        String salt1 = username;
        String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex();
        int hashIterations = 2;

        SimpleHash hash = new SimpleHash(algorithmName, password, salt1 + salt2, hashIterations);
        String encodedPassword = hash.toHex();
        System.out.println(salt2);
View Full Code Here


            }
            return ByteSource.Util.bytes(bytes);
        }

        if (generateSalt) {
            SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
            int byteSize = generatedSaltSize / 8; //generatedSaltSize is in *bits* - convert to byte size:
            return generator.nextBytes(byteSize);
        }

        //no salt used:
        return null;
    }
View Full Code Here

     */
    public DefaultHashService() {
        this.algorithmName = "SHA-512";
        this.iterations = 1;
        this.generatePublicSalt = false;
        this.rng = new SecureRandomNumberGenerator();
    }
View Full Code Here

    }

    public static String issueRandomAPIToken() {
        // we need to see our tokens with a random value so the same one isn't generated
        // for the same user each time.
        RandomNumberGenerator rng = new SecureRandomNumberGenerator();
        Object randomNumber = rng.nextBytes();

        // we also use a user agent as a validation factor
        // so when we later validate the token, we also validate the user agent
        String secret = generateRandomString();
        String salt = secret.concat(randomNumber.toString());
View Full Code Here

    }
   
    @Test
    public void testSaltGenerator() {
   
        RandomNumberGenerator numGen = new SecureRandomNumberGenerator();
        ByteSource src = numGen.nextBytes();
       
        System.err.println(src);
        System.err.println(src.getBytes());
        System.err.println(src.getClass());
    }
View Full Code Here

                    .userRole(UserRole.ADMIN)
                    .build();

            userManager.create(newUser);

            RandomNumberGenerator numberGenerator = new SecureRandomNumberGenerator();
            ByteSource salt = numberGenerator.nextBytes();

            String hashedPassword = new Sha256Hash("haxx", salt, 1024).toBase64();

            Password newPassword = new Password(newUser.getId(), hashedPassword, salt.getBytes());
View Full Code Here

     * not guaranteed the resulting string will resemble the size of the input
     * @return the string of alphanumeric characters
     */
    public static String generateRandomByteKey(int numberOfBytes) {

        return new SecureRandomNumberGenerator()
                .nextBytes(numberOfBytes)
                .toBase64()
                .replaceAll("[^A-Za-z0-9]", "");
    }
View Full Code Here

        /*
         * Create a salt, and use it to create a hashed password for the user.
         * Finally, store the hashed password and its salt in the database.
         */
        ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
        String hashedPassword = new Sha256Hash(password, salt, 1024).toBase64();

        Password newPassword = new Password(userID, hashedPassword, salt.getBytes());

        return newPassword;
View Full Code Here

            }
            return ByteSource.Util.bytes(bytes);
        }

        if (generateSalt) {
            SecureRandomNumberGenerator generator = new SecureRandomNumberGenerator();
            int byteSize = generatedSaltSize / 8; //generatedSaltSize is in *bits* - convert to byte size:
            return generator.nextBytes(byteSize);
        }

        //no salt used:
        return null;
    }
View Full Code Here

     */
    public DefaultHashService() {
        this.algorithmName = "SHA-512";
        this.iterations = 1;
        this.generatePublicSalt = false;
        this.rng = new SecureRandomNumberGenerator();
    }
View Full Code Here

TOP

Related Classes of org.apache.shiro.crypto.SecureRandomNumberGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.