A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Code Examples of PBEParameterSpec


    public void testPBEParameterSpec() {
        byte[] salt = {1, 2, 3, 4, 5};
        int iterationCount = 10;

        try {
            new PBEParameterSpec(null, iterationCount);
            fail("A NullPointerException should be was thrown "
                    + "in the case of null salt.");
        } catch (NullPointerException e) {
        }

        PBEParameterSpec pbeps = new PBEParameterSpec(salt, iterationCount);
        salt[0] ++;
        assertFalse("The change of salt specified in the constructor "
                    + "should not cause the change of internal array.",
                    salt[0] == pbeps.getSalt()[0]);
   }

    /**
     * getSalt() method testing. Tests that returned salt is equal
     * to the salt specified in the constructor and that the change of

View Full Code Here


    public String encode(String userName, String clearTextPassword) throws SecurityException
    {
        try
        {
            // prevent dictionary attacks as well as copying of encoded passwords by using the userName as salt
            PBEParameterSpec cipherSpec = new PBEParameterSpec(createSalt(userName.getBytes("UTF-8")), PKCS_5_ITERATIONCOUNT);
            
            Cipher cipher = Cipher.getInstance(CIPHER_ALGORITM);
            cipher.init(Cipher.ENCRYPT_MODE,pbeKey,cipherSpec);
            
            return new String(Base64.encodeBase64(cipher.doFinal(clearTextPassword.getBytes("UTF-8"))), "UTF-8");

View Full Code Here


            SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
            ecipher = Cipher.getInstance(key.getAlgorithm());
            dcipher = Cipher.getInstance(key.getAlgorithm());

            // Prepare the parameter to the ciphers
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);

            // Create the ciphers
            ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
            dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
        } catch (java.security.InvalidAlgorithmParameterException e) {

View Full Code Here


	private char[] decode(String secret) throws Exception {
		if (!this.encryptionInUse) {
			return secret.toCharArray();
		}
		// Create the PBE secret key
		PBEParameterSpec cipherSpec = new PBEParameterSpec(this.salt, this.iterationCount);
		PBEKeySpec keySpec = new PBEKeySpec(this.pbepass);
		SecretKeyFactory factory = SecretKeyFactory.getInstance(this.pbealgo);
		SecretKey cipherKey = factory.generateSecret(keySpec);
		// Decode the secret
		byte[] encoding = Base64Utils.fromb64(secret);

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


   */
  public DefaultCryptor()
    throws NoSuchAlgorithmException,InvalidKeySpecException
  {
    // Create PBE parameter set
    pbeParamSpec = new PBEParameterSpec(salt,count);
    pbeKeySpec = new PBEKeySpec("saagar".toCharArray());
    keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    pbeKey = keyFac.generateSecret(pbeKeySpec);
  }

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


            // changed only this line of code, which went :
            // ecipher = Cipher.getInstance( key.getAlgorithm() ); and raised an exception
            dcipher = Cipher.getInstance( "PBEWithMD5AndDES" );

            // Prepare the parameters to the ciphers
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec( salt, iterationCount );

            ecipher.init( Cipher.ENCRYPT_MODE, key, paramSpec );
            dcipher.init( Cipher.DECRYPT_MODE, key, paramSpec );

        }

View Full Code Here


		
			SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
		
			SecretKey key = keyFactory.generateSecret(keySpec);
		
			PBEParameterSpec paramSpec = new PBEParameterSpec( salt, PBE_ITERATIONS );
		
			Cipher cipher = Cipher.getInstance( PBE_ALG );
			
			cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
	

View Full Code Here


	    // create the PBE key
	    final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(method);
	    final SecretKey key = keyFactory.generateSecret(keySpec);

	    // create parameter spec for PBE
	    final PBEParameterSpec paramSpec = new PBEParameterSpec(UTF8.getBytes(salt), 1000 /*ITERATIONS*/);
        
	    // Create a cipher and initialize it for encrypting end decrypting
	    cryptMethod = method;
	    ecipher = Cipher.getInstance(cryptMethod);
	    dcipher = Cipher.getInstance(cryptMethod);

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


        PBEKeySpec pbeKeySpec;
        PBEParameterSpec pbeParamSpec;
        SecretKeyFactory keyFac;

        /* Create PBE parameter set */
        pbeParamSpec = new PBEParameterSpec(salt, iteration_count);

        pbeKeySpec = new PBEKeySpec(password);
        keyFac = SecretKeyFactory.getInstance(PBE_ALGORITHM);
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

View Full Code Here



        // Iteration count
        int count = 20;

        // Create PBE parameter set
        pbeParamSpec = new PBEParameterSpec(salt, count);

        pbeKeySpec = new PBEKeySpec(PWD.toCharArray());
        keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);

View Full Code Here

TOP

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

TOP