FileDocCategorySizeDatePackage
PasswordProtectedInputStream.javaAPI DocAndroid 1.5 API2528Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.util

PasswordProtectedInputStream

public class PasswordProtectedInputStream extends FilterInputStream
This class implements a password-protected input stream. The algorithm used for protection is a Vigenere (repeated-key) cipher. The encrypted data is the result of XOR KEYKEYKEY...

Fields Summary
private byte[]
password
private int
pwdIndex
Constructors Summary
public PasswordProtectedInputStream(InputStream in, byte[] password)
Constructs a new instance of the receiver.

param
in The actual input stream where to read the bytes from.
param
password The password bytes to use to decrypt the input bytes

        super(in);
        this.password = password.clone();
    
Methods Summary
public intread()

        int read = in.read();
        if (read >= 0) {
            read ^= password[pwdIndex];
            pwdIndex = (pwdIndex + 1) % password.length;
        }
        return read;
    
public intread(byte[] b, int off, int len)

        int read = in.read(b, off, len);
        if (read > 0) {
            int lastIndex = off + read;
            for (int i = off; i < lastIndex; i++) {
                b[i] ^= password[pwdIndex];
                pwdIndex = (pwdIndex + 1) % password.length;
            }
        }
        return read;
    
public longskip(long n)

        long skip = super.skip(n);
        pwdIndex += skip;
        return skip;