Package javax.crypto.spec

Examples of javax.crypto.spec.PBEKeySpec


    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);
    Cipher cipher = Cipher.getInstance(this.pbealgo);
View Full Code Here


    try{
      byte[]  salt = new byte[8];
     
      System.arraycopy( data, 0, salt, 0, 8 );
     
      PBEKeySpec keySpec = new PBEKeySpec(password);
 
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
 
      SecretKey key = keyFactory.generateSecret(keySpec);
 
View Full Code Here

    try{
      byte[]  salt = new byte[8];
     
      RandomUtils.SECURE_RANDOM.nextBytes( salt );
     
      PBEKeySpec keySpec = new PBEKeySpec(password);
   
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
   
      SecretKey key = keyFactory.generateSecret(keySpec);
   
View Full Code Here

    }

    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);

        /* Create PBE Cipher */
        Cipher pbeCipher = Cipher.getInstance(PBE_ALGORITHM);
View Full Code Here

    }

    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);

        // Create PBE Cipher
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
View Full Code Here


    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);

        // Create PBE Cipher
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
View Full Code Here

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

    }


    private cryptbig(final String pbe, String salt, final String method) {
  // a Password-Based Encryption. The SecretKey is created on the fly
  final PBEKeySpec keySpec = new PBEKeySpec(pbe.toCharArray());
  try {
      if (salt.length() > 8) salt = salt.substring(0,8);
      if (salt.length() < 8) salt = (salt + "XXXXXXXX").substring(0,8);
     
      // create the PBE key
View Full Code Here

     */
    private Key getCiperKey(byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException {
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        // hashing the password 65K times takes 151ms, hashing 256 times takes 2ms.
        // Since the salt has 2^^72 values, 256 times is probably good enough.
        KeySpec spec = new PBEKeySpec(sharedKey.toCharArray(), salt, 256, 128);
        SecretKey tmp = factory.generateSecret(spec);
        SecretKey key = new SecretKeySpec(tmp.getEncoded(), "AES");
        return key;
    }
View Full Code Here

            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

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.