Code example for Mac

Methods: doFinal, init

0
        } 
        if (outputLengthSet && outputLength < getDigestLength()) {
            throw new XMLSignatureException 
                ("HMACOutputLength must not be less than " + getDigestLength()); 
        } 
        hmac.init((SecretKey) key);
        si.canonicalize(context, new MacOutputStream(hmac));
        byte[] result = hmac.doFinal();
 
        return MessageDigest.isEqual(sig, result);
    } 
 
    byte[] sign(Key key, DOMSignedInfo si, XMLSignContext context)
        throws InvalidKeyException, XMLSignatureException { 
        if (key == null || si == null) {
            throw new NullPointerException();
        } 
        if (!(key instanceof SecretKey)) {
            throw new InvalidKeyException("key must be SecretKey");
        } 
        if (hmac == null) {