FileDocCategorySizeDatePackage
CipherPBEThread.javaAPI DocAndroid 1.5 API2177Wed May 06 22:41:02 BST 2009org.apache.harmony.crypto.tests.javax.crypto.func

CipherPBEThread

public class CipherPBEThread extends CipherThread

Fields Summary
Constructors Summary
CipherPBEThread(String name, int[] keys, String[] modes, String[] paddings)

        super(name, keys, modes, paddings);
    
Methods Summary
public voidcrypt()

        byte[] output = new byte[128];
        byte[] decrypted = new byte[128];
        byte[] input  =  getData().getBytes();
        byte[] salt = new byte[8];
        SecureRandom sr = new SecureRandom();

        PBEKeySpec keySpec = new PBEKeySpec("top sicret password".toCharArray());
        SecretKeyFactory skf = SecretKeyFactory.getInstance(getAlgName()); 
        SecretKey key = skf.generateSecret(keySpec);

        Cipher cip = Cipher.getInstance(getAlgName() + "/" + getMode() + "/" +
                getPadding());
        
        sr.nextBytes(salt);
        PBEParameterSpec parSpec = new PBEParameterSpec(salt, getKeyLength());

        cip.init(Cipher.ENCRYPT_MODE, key, parSpec);
        cip.doFinal(input, 0, input.length, output);
        int outputSize = cip.getOutputSize(input.length);
        cip.init(Cipher.DECRYPT_MODE, key, parSpec);
        cip.doFinal(output, 0, outputSize, decrypted);

        checkEncodedData(getData().getBytes(), decrypted);