FileDocCategorySizeDatePackage
JCEMac.javaAPI DocAndroid 1.5 API11376Wed May 06 22:41:06 BST 2009org.bouncycastle.jce.provider

JCEMac

public class JCEMac extends MacSpi implements PBE

Fields Summary
private org.bouncycastle.crypto.Mac
macEngine
private int
pbeType
private int
pbeHash
private int
keySize
Constructors Summary
protected JCEMac(org.bouncycastle.crypto.Mac macEngine)


     
         
    
        this.macEngine = macEngine;
    
protected JCEMac(org.bouncycastle.crypto.Mac macEngine, int pbeType, int pbeHash, int keySize)

        this.macEngine = macEngine;
        this.pbeType = pbeType;
        this.pbeHash = pbeHash;
        this.keySize = keySize;
    
Methods Summary
protected byte[]engineDoFinal()

        byte[]  out = new byte[engineGetMacLength()];

        macEngine.doFinal(out, 0);

        return out;
    
protected intengineGetMacLength()

        return macEngine.getMacSize();
    
protected voidengineInit(java.security.Key key, java.security.spec.AlgorithmParameterSpec params)

        CipherParameters        param;

        if (key == null)
        {
            throw new InvalidKeyException("key is null");
        }
        
        if (key instanceof JCEPBEKey)
        {
            JCEPBEKey   k = (JCEPBEKey)key;
            
            if (k.getParam() != null)
            {
                param = k.getParam();
            }
            else if (params instanceof PBEParameterSpec)
            {
                param = PBE.Util.makePBEMacParameters(k, params);
            }
            else
            {
                throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set.");
            }
        }
        else if (params instanceof IvParameterSpec)
        {
            param = new ParametersWithIV(new KeyParameter(key.getEncoded()), ((IvParameterSpec)params).getIV());
        }
        else if (params == null)
        {
            param = new KeyParameter(key.getEncoded());
        }
        else
        {
            throw new InvalidAlgorithmParameterException("unknown parameter type.");
        }

        macEngine.init(param);
    
protected voidengineReset()

        macEngine.reset();
    
protected voidengineUpdate(byte input)

        macEngine.update(input);
    
protected voidengineUpdate(byte[] input, int offset, int len)

        macEngine.update(input, offset, len);