Package javax.crypto

Examples of javax.crypto.SecretKeyFactory.generateSecret()


      // Create the PBE secret key
      cipherSpec = new PBEParameterSpec(salt, iterationCount);
      PBEKeySpec keySpec = new PBEKeySpec(keyStorePassword);
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
      cipherKey = factory.generateSecret(keySpec);
   }
  
   private void loadKeyAndTrustStore()
      throws Exception
   {
View Full Code Here


    public String createPasswordKey(char[] password, byte[] salt, int iterations)
            throws GeneralSecurityException {
        if (hashAlgorithm != null) {
            PBEKeySpec passwordKeySpec = new PBEKeySpec(password, salt, iterations, 256);
            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(hashAlgorithm);
            SecretKey passwordKey = secretKeyFactory.generateSecret(passwordKeySpec);
            passwordKeySpec.clearPassword();
            return BinTools.bin2hex(passwordKey.getEncoded());
        } else {
            PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA1", "ISO-8859-1", salt, iterations);
            PBKDF2 pbkdf2 = new PBKDF2Engine(params);
View Full Code Here

        Key secretKey;
        try {
            if (algorithm.equalsIgnoreCase("DESede")) {
                keySpec = new DESedeKeySpec(passPhrase);
                SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
                secretKey = keyFactory.generateSecret(keySpec);
            } else if (algorithm.equalsIgnoreCase("SEED")) {
                secretKey = new SecretKeySpec(passPhrase, "SEED");
            } else if (algorithm.equalsIgnoreCase("CAMELLIA")) {
                secretKey = new SecretKeySpec(passPhrase, "CAMELLIA");
            } else {
View Full Code Here

  private static Key getKey() {
    try {
      byte[] bytes = getBytes(KEY_STRING);
      DESKeySpec pass = new DESKeySpec(bytes);
      SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); //$NON-NLS-1$
      SecretKey s = skf.generateSecret(pass);
      return s;
    } catch (Exception e) {
            Debug.error(e.toString());
    }
    return null;
View Full Code Here

    public static byte[] hashPassword(String password, byte[] salt) {
        try {
            PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH);
            SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
            return skf.generateSecret(spec).getEncoded();
        } catch (InvalidKeySpecException e) {
            throw new RuntimeException("Invalid key spec", e);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Could not find algorithm", e);
        }
View Full Code Here

        throws Exception
    {
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(oid.getId(), provider);
        PBEParameterSpec defParams = new PBEParameterSpec(salt, itCount);
        PBEKeySpec pbeSpec = new PBEKeySpec(password);
        SecretKey key = keyFact.generateSecret(pbeSpec);

        Mac mac = Mac.getInstance(oid.getId(), provider);
        mac.init(key, defParams);
        mac.update(data);
View Full Code Here

            SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
            PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);

            Cipher cipher = Cipher.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);

            cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams);

            return cipher;
        }
        catch (Exception e)
        {
View Full Code Here

                    algorithm.getId(), bcProvider);
                PBEParameterSpec defParams = new PBEParameterSpec(
                    pbeParams.getIV(),
                    pbeParams.getIterations().intValue());

                SecretKey k = keyFact.generateSecret(pbeSpec);

                ((BCPBEKey)k).setTryWrongPKCS12Zero(wrongPKCS12Zero);

                Cipher cipher = Cipher.getInstance(algorithm.getId(), bcProvider);
View Full Code Here

                PBES2Parameters alg = PBES2Parameters.getInstance(algId.getParameters());
                PBKDF2Params func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());

                SecretKeyFactory keyFact = SecretKeyFactory.getInstance(alg.getKeyDerivationFunc().getAlgorithm().getId(), bcProvider);

                SecretKey k = keyFact.generateSecret(new PBEKeySpec(password, func.getSalt(), func.getIterationCount().intValue(), SecretKeyUtil.getKeySize(alg.getEncryptionScheme().getAlgorithm())));

                Cipher cipher = Cipher.getInstance(alg.getEncryptionScheme().getAlgorithm().getId(), bcProvider);

                cipher.init(Cipher.UNWRAP_MODE, k, new IvParameterSpec(ASN1OctetString.getInstance(alg.getEncryptionScheme().getParameters()).getOctets()));
View Full Code Here

                pbeParams.getIV(),
                pbeParams.getIterations().intValue());

            Cipher cipher = Cipher.getInstance(algorithm, bcProvider);

            cipher.init(Cipher.WRAP_MODE, keyFact.generateSecret(pbeSpec), defParams);

            out = cipher.wrap(key);
        }
        catch (Exception e)
        {
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.