Examples of PBEParameterSpec


Examples of javax.crypto.spec.PBEParameterSpec

  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

Examples of javax.crypto.spec.PBEParameterSpec

   
      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

Examples of javax.crypto.spec.PBEParameterSpec

 
      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.DECRYPT_MODE, key, paramSpec);
 
View Full Code Here

Examples of javax.crypto.spec.PBEParameterSpec

    private static Cipher getCipher(int mode, char[] password)
            throws Exception {

        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

Examples of javax.crypto.spec.PBEParameterSpec

    private static byte[] getEncrypted(String plaintext)
        throws Exception {

        PBEKeySpec pbeKeySpec;
        PBEParameterSpec pbeParamSpec;
        SecretKeyFactory keyFac;

        // Salt
        byte[] salt = {
            (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
            (byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99
        };

        // 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

Examples of javax.crypto.spec.PBEParameterSpec

    private static String getDecrypted(byte[] cyphertext)
        throws Exception {

        PBEKeySpec pbeKeySpec;
        PBEParameterSpec pbeParamSpec;
        SecretKeyFactory keyFac;

        // Salt
        byte[] salt = {
            (byte) 0xc7, (byte) 0x73, (byte) 0x21, (byte) 0x8c,
            (byte) 0x7e, (byte) 0xc8, (byte) 0xee, (byte) 0x99
        };

        // 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

Examples of javax.crypto.spec.PBEParameterSpec

    * @throws Exception if an error ocurrs when loading the PBE key.
    */
   private void loadPBESecretKey() throws Exception
   {
      // Create the PBE secret key
      cipherSpec = new PBEParameterSpec(salt, iterationCount);
      PBEKeySpec keySpec = new PBEKeySpec(keyStorePassword);
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
      cipherKey = factory.generateSecret(keySpec);
   }
View Full Code Here

Examples of javax.crypto.spec.PBEParameterSpec

      // 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

Examples of javax.crypto.spec.PBEParameterSpec

         else
            throw new IllegalArgumentException("Unknown keyStorePasswordCmdType: "+keyStorePasswordCmdType);
      }

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

Examples of javax.crypto.spec.PBEParameterSpec

      NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
    KeySpec keySpec = new PBEKeySpec(passphrase.toCharArray());
    SecretKey key = SecretKeyFactory.getInstance(KEY_ALGORITHM, bouncyCastleProvider).generateSecret(keySpec);

    Cipher cipher = Cipher.getInstance(KEY_ALGORITHM, bouncyCastleProvider);
    PBEParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);

    cipher.init(mode, key, paramSpec);
    return cipher;
  }
View Full Code Here
TOP
Copyright © 2015 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.