Code example for InvalidKeyException

0
        byte[] encoded = key.getEncoded();
        if (encoded == null)
        { 
            throw new InvalidKeyException("Cannot wrap key, null encoding.");
        } 
 
        try 
        { 
            if (wrapEngine == null)
            { 
                return engineDoFinal(encoded, 0, encoded.length);
            } 
            else 
            { 
                return wrapEngine.wrap(encoded, 0, encoded.length);
            } 
        } 
        catch (BadPaddingException e)
        { 
            throw new IllegalBlockSizeException(e.getMessage());
        }