Package org.apache.shiro.util

Examples of org.apache.shiro.util.ByteSource


     * @param key      the key used to encrypt the password
     * @return decrypted password in plain text
     */
    public static String decryptPassword(String password, byte[] key) {
        AesCipherService cipherService = new AesCipherService();
        ByteSource decrypted = cipherService.decrypt(Base64.decode(password), key);
        return new String(decrypted.getBytes());
    }
View Full Code Here


                    .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());

            passwordManager.create(newPassword);

            FireLogger.logInfo(
                    "Created debug user "
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

        /*
         * 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

                } else {
                    iterations = DEFAULT_NUM_ITERATIONS;
                }
            }

            ByteSource salt = getSalt(saltString, saltBytesString, generateSalt, generatedSaltSize);

            SimpleHash hash = new SimpleHash(algorithm, source, salt, iterations);

            if (formatString == null) {
                //Output format was not specified.  Default to 'shiro1' when password hashing, and 'hex' for
View Full Code Here

     */
    protected byte[] encrypt(byte[] serialized) {
        byte[] value = serialized;
        CipherService cipherService = getCipherService();
        if (cipherService != null) {
            ByteSource byteSource = cipherService.encrypt(serialized, getEncryptionCipherKey());
            value = byteSource.getBytes();
        }
        return value;
    }
View Full Code Here

     */
    protected byte[] decrypt(byte[] encrypted) {
        byte[] serialized = encrypted;
        CipherService cipherService = getCipherService();
        if (cipherService != null) {
            ByteSource byteSource = cipherService.decrypt(encrypted, getDecryptionCipherKey());
            serialized = byteSource.getBytes();
        }
        return serialized;
    }
View Full Code Here

        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());
View Full Code Here

        String saltBase64 = parts[i--];
        String iterationsString = parts[i--];
        String algorithmName = parts[i];

        byte[] digest = Base64.decode(digestBase64);
        ByteSource salt = null;

        if (StringUtils.hasLength(saltBase64)) {
            byte[] saltBytes = Base64.decode(saltBase64);
            salt = ByteSource.Util.bytes(saltBytes);
        }
View Full Code Here

        checkHashFormatDurability();
        return this.hashFormat.format(hash);
    }

    public Hash hashPassword(Object plaintext) {
        ByteSource plaintextBytes = createByteSource(plaintext);
        if (plaintextBytes == null || plaintextBytes.isEmpty()) {
            return null;
        }
        HashRequest request = createHashRequest(plaintextBytes);
        return hashService.computeHash(request);
    }
View Full Code Here

TOP

Related Classes of org.apache.shiro.util.ByteSource

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.