FileDocCategorySizeDatePackage
XORCipher.javaAPI DocExample2590Sun Jan 14 22:15:04 GMT 2001javasec.samples.ch13

XORCipher

public class XORCipher extends CipherSpi

Fields Summary
byte
xorByte
Constructors Summary
public XORCipher()

        XYZProvider.verifyForJCE();
    
Methods Summary
protected byte[]engineDoFinal(byte[] in, int off, int len)

        byte out[] = new byte[len - off];
        engineUpdate(in, off, len, out, 0);
        return out;
    
protected intengineDoFinal(byte[] in, int inoff, int len, byte[] out, int outoff)

        return engineUpdate(in, inoff, len, out, outoff);
    
protected intengineGetBlockSize()

        return 1;
    
protected byte[]engineGetIV()

        return null;
    
protected intengineGetOutputSize(int sz)

        return sz;
    
protected java.security.AlgorithmParametersengineGetParameters()

        return null;
    
protected voidengineInit(int i, java.security.Key k, java.security.SecureRandom sr)

        if (!(k instanceof XORKey))
            throw new InvalidKeyException("XOR requires an XOR key");
        xorByte = k.getEncoded()[0];
    
protected voidengineInit(int i, java.security.Key k, java.security.spec.AlgorithmParameterSpec aps, java.security.SecureRandom sr)

        throw new InvalidAlgorithmParameterException(
            "Algorithm parameters not supported in this class");
    
protected voidengineInit(int i, java.security.Key k, java.security.AlgorithmParameters ap, java.security.SecureRandom sr)

        throw new InvalidAlgorithmParameterException(
            "Algorithm parameters not supported in this class");
    
protected voidengineSetMode(java.lang.String s)

        throw new NoSuchAlgorithmException("Unsupported mode " + s);
    
protected voidengineSetPadding(java.lang.String s)

        throw new NoSuchPaddingException("Unsupported padding " + s);
    
protected byte[]engineUpdate(byte[] in, int off, int len)

        return engineDoFinal(in, off, len);
    
protected intengineUpdate(byte[] in, int inoff, int length, byte[] out, int outoff)

        for (int i = 0; i < length; i++)
            out[outoff + i] = (byte) (in[inoff + i] ^ xorByte);
        return length;