Examples of PBEKey


Examples of javax.crypto.interfaces.PBEKey

  static final int KEY_LENGTH = 128;

  public static byte[] doPasswordHash(String password) {
    byte[] salt = CryptoUtils.generateSecureRandom(SALT_LENGTH);
    int iterationCount = 1000;
    PBEKey key = KeyDerivationFunctions.doPbkdf2(iterationCount, salt, password, KEY_LENGTH);

    return CryptoUtils.concat(salt, key.getEncoded());
  }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

    }

    byte[] salt = Arrays.copyOfRange(hashed, 0, SALT_LENGTH);

    int iterationCount = 1000;
    PBEKey key = KeyDerivationFunctions.doPbkdf2(iterationCount, salt, password, KEY_LENGTH);

    byte[] data = key.getEncoded();

    if ((data.length + SALT_LENGTH) != hashed.length) {
      return false;
    }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

  static SecretKeySpec deriveHmacSha1Key(String keyData) {
    // We want a consistent salt; it can't be empty
    byte[] salt = Utf8.getBytes(keyData);
    int keySize = 128; // ??
    int iterationCount = 1000;
    PBEKey pbeKey = KeyDerivationFunctions.doPbkdf2(iterationCount, salt, keyData, keySize);

    return CryptoUtils.buildHmacSha1Key(pbeKey.getEncoded());
  }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

    return key;
  }

  public static SecretKey deriveKey(byte[] salt, String password) {
    int iterationCount = 1000;
    PBEKey pbeKey = KeyDerivationFunctions.doPbkdf2(iterationCount, salt, password, DEFAULT_KEYSIZE);
    SecretKey secretKey = new SecretKeySpec(pbeKey.getEncoded(), ALGORITHM);
    return secretKey;
  }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

        try {
            factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Unable to get PBKDF2 provider", e);
        }
        PBEKey key;
        try {
            key = (PBEKey) factory.generateSecret(pbeKeySpec);
        } catch (InvalidKeySpecException e) {
            throw new IllegalStateException("Error generating secret", e);
        }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

    public boolean isValid(PasswordHashData passwordHash, String password) {
        byte[] salt = passwordHash.getSalt().toByteArray();
        int rounds = passwordHash.getRounds();
        int keySize = DEFAULT_KEYSIZE;

        PBEKey key = doPbkdf2(rounds, salt, password, keySize);
        byte[] encoded = key.getEncoded();
        byte[] stored = passwordHash.getData().toByteArray();

        return org.keyczar.util.Util.safeArrayEquals(encoded, stored);
    }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

        int keySize = DEFAULT_KEYSIZE;

        hasher.setSalt(ByteString.copyFrom(salt));
        hasher.setRounds(rounds);

        PBEKey key = doPbkdf2(rounds, salt, password, keySize);
        byte[] encoded = key.getEncoded();

        hasher.setData(ByteString.copyFrom(encoded));

        return hasher.build();
    }
View Full Code Here

Examples of javax.crypto.interfaces.PBEKey

            throw new Exception("decryption test for " + alg + " failed");
        }

        PBEParameterSpec spec = (PBEParameterSpec)
            pbeParams.getParameterSpec(PBEParameterSpec.class);
        PBEKey key2 = new
            MyPBEKey(password, spec.getSalt(), spec.getIterationCount());
        cipher.init(Cipher.DECRYPT_MODE, key2, pbeParams);
        byte[] dec2 = cipher.doFinal(enc1);
        if (Arrays.equals(dec2, dec) == false) {
            throw new Exception("Re-decryption test#1 failed");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.