Package javax.crypto.spec

Examples of javax.crypto.spec.PBEParameterSpec


        int     iterationCount)
        throws Exception
    {
        PBEKeySpec          pbeSpec = new PBEKeySpec(password);
        SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(algorithm, "BC");
        PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);

        Cipher cipher = Cipher.getInstance(algorithm, "BC");

        cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams);
View Full Code Here


            return;
        }

        try
        {
            mac.init(key, new PBEParameterSpec(new byte[20], 100));
        }
        catch (Exception e)
        {
            fail("Failed - exception " + e.toString(), e);
            return;
View Full Code Here

        private AlgorithmParameters checkParameters(Cipher c, byte[] salt, int iCount)
            throws InvalidParameterSpecException
        {
            AlgorithmParameters param = c.getParameters();
            PBEParameterSpec spec = (PBEParameterSpec)param.getParameterSpec(PBEParameterSpec.class);

            if (!arrayEquals(salt, spec.getSalt()))
            {
                fail("" + algorithm + "failed salt test");
            }

            if (iCount != spec.getIterationCount())
            {
                fail("" + algorithm + "failed count test");
            }
            return param;
        }
View Full Code Here

    {
        try
        {
            PBEKeySpec          pbeSpec = new PBEKeySpec(password);
            SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(algorithm, "BC");
            PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);

            Cipher cipher = Cipher.getInstance(algorithm, "BC");

            cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams);
View Full Code Here

        // Create the PBE secret key
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");

        char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray();
        PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount);
        PBEKeySpec keySpec = new PBEKeySpec(password);
        SecretKey cipherKey = factory.generateSecret(keySpec);

        String maskedPass = PBEUtils.encode64(passwd.getBytes(), algo, cipherKey, cipherSpec);
View Full Code Here

  @Override
  protected final byte[] crypt(final byte[] input, final int mode)
    throws GeneralSecurityException
  {
    SecretKey key = generateSecretKey();
    PBEParameterSpec spec = new PBEParameterSpec(salt, COUNT);
    Cipher ciph = Cipher.getInstance(CRYPT_METHOD);
    ciph.init(mode, key, spec);
    return ciph.doFinal(input);
  }
View Full Code Here

    /**
     * Initializes the Cipher for use.
     */
    public static void initCipher(Cipher cipher, int mode, SecretKey secretKey, byte[] salt, int iterationCount) {
        initCipher(cipher, mode, secretKey, new PBEParameterSpec(salt, iterationCount));
    }
View Full Code Here

      KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), this.salt, this.iterationCount);
      SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
      this.ecipher = Cipher.getInstance(key.getAlgorithm());
      this.dcipher = Cipher.getInstance(key.getAlgorithm());
      // Prepare the parameter to the ciphers
      AlgorithmParameterSpec paramSpec = new PBEParameterSpec(this.salt, this.iterationCount);
      // Create the ciphers
      this.ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
      this.dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
    } catch (InvalidAlgorithmParameterException e) {
    } catch (InvalidKeySpecException e) {
View Full Code Here

    private Cipher getCipher(int mode, String password) throws Exception
    {
        final Random random = new Random(43287234L);
        final byte[] salt = new byte[8];
        random.nextBytes(salt);
        final PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
       
        final SecretKey pbeKey = SecretKeyFactory.getInstance(
                "PBEWithMD5AndDES").generateSecret(
                new PBEKeySpec(password.toCharArray()));
        final Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
View Full Code Here

    }

    @Override
    public void start() {
        try {
            this.cipherSpec = new PBEParameterSpec(salt, iterationCount);
            PBEKeySpec keySpec = new PBEKeySpec(keyStorePassword);
            SecretKeyFactory factory = SecretKeyFactory.getInstance(cipherAlgorithm);
            this.cipherKey = factory.generateSecret(keySpec);
        } catch (Exception e) {
            log.error("Error starting EncoderService", e);
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.