Package javax.crypto.spec

Examples of javax.crypto.spec.PBEKeySpec


   static void encode(RandomAccessFile passwordFile, byte[] salt, int count,
      byte[] secret)
      throws Exception
   {
      PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count);
      PBEKeySpec keySpec = new PBEKeySpec("78aac249a60a13d5e882927928043ebb".toCharArray());
      SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES");
      SecretKey cipherKey = factory.generateSecret(keySpec);
      Cipher cipher = Cipher.getInstance("PBEwithMD5andDES");
      cipher.init(Cipher.ENCRYPT_MODE, cipherKey, cipherSpec);
      byte[] encode = cipher.doFinal(secret);
View Full Code Here


  public String encryptPassword(final String password, final String key)
      throws GeneralSecurityException, UnsupportedEncodingException
  {
    final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    final KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT, 1024, 128);
    final SecretKey tmp = factory.generateSecret(spec);
    final SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
    return encryptPassword(password, secret, "AES/CBC/PKCS5PADDING");
  }
View Full Code Here

  public String decryptPassword(final String password,
                                final String key) throws UnsupportedEncodingException, GeneralSecurityException
  {
    final SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    final KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT, 1024, 128);
    final SecretKey tmp = factory.generateSecret(spec);
    final SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
    return decryptPassword(password, secret, "AES/CBC/PKCS5PADDING");
  }
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);
View Full Code Here

        int iterationCount = 19;

        try
        {

            KeySpec keySpec = new PBEKeySpec( passPhrase.toCharArray(), salt, iterationCount );
            SecretKey key = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" ).generateSecret( keySpec );

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

        return in;
      }

      final String algorithm = "PBEWithSHA256And192BitAES-CBC-BC";
        final Cipher c = Cipher.getInstance(algorithm, "BC");
        final PBEKeySpec          keySpec = new PBEKeySpec(p, getSalt(), iCount);
        final SecretKeyFactory    fact = SecretKeyFactory.getInstance(algorithm, "BC");
       
        c.init(Cipher.DECRYPT_MODE, fact.generateSecret(keySpec));
       
        final byte[] dec = c.doFinal(Hex.decode(in.getBytes("UTF-8")));
View Full Code Here

        paramSpec = new PBEParameterSpec(SALT, ITERATION);
    }

    @Override
    public void initKey() throws Exception {
        KeySpec keySpec = new PBEKeySpec(password.toCharArray());
        skey = SecretKeyFactory.getInstance(algorithm).generateSecret(keySpec);
    }
View Full Code Here

            byte[] saltArray = decoder.decodeBuffer(saltString);
            byte[] cipherTextArray = decoder.decodeBuffer(cipherText);
            char[] passwordChar = password.toCharArray();

            // Create the PBEKeySpec with the given password
            PBEKeySpec keySpec = new PBEKeySpec(passwordChar);

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

            byte[] saltArray = decoder.decodeBuffer(saltString);
            byte[] cipherTextArray = decoder.decodeBuffer(cipherText);
            char[] passwordChar = password.toCharArray();

            // Create the PBEKeySpec with the given password
            PBEKeySpec keySpec = new PBEKeySpec(passwordChar);

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

        }
    }

    void unlock(char[] masterPassword) throws Exception {
        LOG.fine("switching to new master password");
        KeySpec keySpec = new PBEKeySpec(masterPassword);
        Key key = KEY_FACTORY.generateSecret(keySpec);
        encrypt.init(Cipher.ENCRYPT_MODE, key, PARAM_SPEC);
        decrypt.init(Cipher.DECRYPT_MODE, key, PARAM_SPEC);
        unlocked = true;
    }
View Full Code Here

TOP

Related Classes of javax.crypto.spec.PBEKeySpec

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.