Package javax.crypto.spec

Examples of javax.crypto.spec.PBEParameterSpec


    public PBEEncrypter(int keySize, String algorithm, String password) {
        super(algorithm, keySize, null);
        this.password = password;
        Random random = new Random();
        random.nextBytes(SALT);
        paramSpec = new PBEParameterSpec(SALT, ITERATION);
    }
View Full Code Here


            // Get a SecretFactory for PBEWithSHAAndTwofish
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(this.algorithm);
            skey = keyFactory.generateSecret(keySpec);

            // Now create a parameter spec for our salt and iterations
            PBEParameterSpec paramSpec = new PBEParameterSpec(saltArray, ITERATION);
            cipher.init(Cipher.DECRYPT_MODE, skey, paramSpec);

            // perform the actual decryption
            byte[] plainTextArray = cipher.doFinal(cipherTextArray);
            return plainTextArray;
View Full Code Here

            // Get a SecretFactory for PBEWithSHAAndTwofish
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(this.algorithm);
            skey = keyFactory.generateSecret(keySpec);

            // Now create a parameter spec for our salt and iterations
            PBEParameterSpec paramSpec = new PBEParameterSpec(saltArray, ITERATION);
            cipher.init(Cipher.DECRYPT_MODE, skey, paramSpec);

            byte[] plainTextArray = cipher.doFinal(cipherTextArray);
            writeByte(new File(outputFile), plainTextArray);
        } catch (Exception e) {
View Full Code Here

            byte[] salt = prefs.getByteArray(saltKey, null);
            if (salt == null) {
                salt = UUID.randomUUID().toString().getBytes();
                prefs.putByteArray(saltKey, salt);
            }
            PARAM_SPEC = new PBEParameterSpec(salt, 20);
            LOG.warning("Falling back to master password encryption; " +
                    "add -J-Dorg.netbeans.modules.keyring.level=0 to netbeans.conf to see why native keyrings could not be loaded");
            return true;
        } catch (Exception x) {
            LOG.log(Level.INFO, "Cannot initialize security using " + ENCRYPTION_ALGORITHM, x);
View Full Code Here

            Class paramSpec)
            throws InvalidParameterSpecException
        {
            if (paramSpec == PBEParameterSpec.class)
            {
                return new PBEParameterSpec(params.getIV(),
                                params.getIterations().intValue());
            }

            throw new InvalidParameterSpecException("unknown parameter spec passed to PKCS12 PBE parameters object.");
        }
View Full Code Here

            if (!(paramSpec instanceof PBEParameterSpec))
            {
                throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");
            }

            PBEParameterSpec    pbeSpec = (PBEParameterSpec)paramSpec;

            this.params = new PKCS12PBEParams(pbeSpec.getSalt(),
                                pbeSpec.getIterationCount());
        }
View Full Code Here

      Object[] args = {secret};
      String[] sig = {secret.getClass().getName()};
      byte[] encode = (byte[]) super.invoke(name, "encode", args, sig);
      assertTrue("secret != encode", Arrays.equals(secret, encode) == false);

      PBEParameterSpec cipherSpec = new PBEParameterSpec("abcdefgh".getBytes(), 13);
      PBEKeySpec keySpec = new PBEKeySpec("password1".toCharArray());
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
      SecretKey cipherKey = factory.generateSecret(keySpec);
      Cipher cipher = Cipher.getInstance("PBEwithMD5andDES");
      cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
View Full Code Here

      Object[] args = {secret};
      String[] sig = {secret.getClass().getName()};
      byte[] encode = (byte[]) super.invoke(name, "encode", args, sig);
      assertTrue("secret != encode", Arrays.equals(secret, encode) == false);

      PBEParameterSpec cipherSpec = new PBEParameterSpec("abcdefgh".getBytes(), 13);
      PBEKeySpec keySpec = new PBEKeySpec("password2".toCharArray());
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
      SecretKey cipherKey = factory.generateSecret(keySpec);
      Cipher cipher = Cipher.getInstance("PBEwithMD5andDES");
      cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
View Full Code Here

        return new PBEKeySpec(password);
    }

    protected AlgorithmParameterSpec createAlgorithmParameterSpec()
    {
        return new PBEParameterSpec(salt, iterationCount);
    }
View Full Code Here

                                          salt_v1,
                                          KEY_ITERATION_COUNT_V1,
                                          32);
      SecretKeyFactory skf = SecretKeyFactory.getInstance(KEY_FACTORY_V1);
      SecretKey key = skf.generateSecret(keyspec);
      AlgorithmParameterSpec aps = new PBEParameterSpec(salt_v1,
                                                        KEY_ITERATION_COUNT_V1);
      cipher = Cipher.getInstance(KEY_FACTORY_V1);
      cipher.init(Cipher.DECRYPT_MODE, key, aps);
    } catch (Exception ex) {
      Log.d(LOG_TAG, "createDecryptionCiphersV1", ex);
View Full Code Here

TOP

Related Classes of javax.crypto.spec.PBEParameterSpec

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.