Code example for Mac

Methods: clonedoFinalgetMacLengthinitreset

0
        Security.removeProvider(mProv.getName());
    } 
     
    protected void checkResult(Mac mac) throws InvalidKeyException,
            InvalidAlgorithmParameterException { 
        assertEquals("Incorrect MacLength", mac.getMacLength(), 0);
        byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
        SecretKeySpec scs = new SecretKeySpec(b, "SHA1");
        AlgParSpec parms = new AlgParSpec();
        tmpKey tKey = new tmpKey();
        mac.init(scs);        
        byte[] bb = mac.doFinal();
        assertEquals(bb.length, 0);
        mac.reset();
        bb = mac.doFinal();
        assertEquals(bb.length, 1);
        try { 
            mac.init(null);
            fail("InvalidKeyException should be thrown");
        } catch (InvalidKeyException e) {
        } 
        try { 
            mac.init(null, null);
            fail("InvalidKeyException should be thrown");
        } catch (InvalidKeyException e) {
        } 
        mac.init(scs, null);
        mac.init(scs, parms);
        try { 
            mac.init(tKey, null);
            fail("InvalidAlgorithmParameterException or IllegalArgumentException "
                    + "should be thrown for incorrect parameter"); 
        } catch (IllegalArgumentException e) {
        } catch (InvalidAlgorithmParameterException e) {
        } 
        try { 
            mac.clone();
            fail("No expected CloneNotSupportedException"); 
        } catch (CloneNotSupportedException e) {           
        } 
    } 
 
Connect your IDE to all the code out there  Get Codota for Java