Package javax.crypto

Examples of javax.crypto.SecretKeyFactory


      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);
    cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
    byte[] decode = cipher.doFinal(encoding);
View Full Code Here


    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

     
      RandomUtils.SECURE_RANDOM.nextBytes( salt );
     
      PBEKeySpec keySpec = new PBEKeySpec(password);
   
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
   
      SecretKey key = keyFactory.generateSecret(keySpec);
   
      PBEParameterSpec paramSpec = new PBEParameterSpec( salt, PBE_ITERATIONS );
   
      Cipher cipher = Cipher.getInstance( PBE_ALG );
     
View Full Code Here

     
      System.arraycopy( data, 0, salt, 0, 8 );
     
      PBEKeySpec keySpec = new PBEKeySpec(password);
 
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
 
      SecretKey key = keyFactory.generateSecret(keySpec);
 
      PBEParameterSpec paramSpec = new PBEParameterSpec(salt, PBE_ITERATIONS);
 
      Cipher cipher = Cipher.getInstance( PBE_ALG );
     
View Full Code Here

        this.encryptedKey = encryptedKey;
        /* get SecretKey from encryptedKey */
        byte[] key = getDecrypted(encryptedKey, password);
        try {
            SecretKeyFactory keyFac = SecretKeyFactory.getInstance(CRYPTO_ALGORITHM);
            this.secretKey = keyFac.generateSecret(new DESedeKeySpec(key));;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
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);

        /* Initialize PBE Cipher with key and parameters */
 
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");

        // Initialize PBE Cipher with key and parameters
View Full Code Here

TOP

Related Classes of javax.crypto.SecretKeyFactory

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.