Consent may be used as a defense in the criminal law - similar to consent in tort law - when the victim might reasonably be shown to have consented to the defendant's actions. This defense can only be valid when the defendant's action is not strictly forbidden by statute, as is the case with many strict liability crimes and so-called consensual crimes (e.g., prostitution may be consensual, but the lady's consent in this case usually doesn't make the act legal). Consent may be given either in written or verbal form and, in certain circumstances, silence can also qualify as consent.
An example of a situation in which consent might hold as a defense would be an employer telling his clerk to take some money from the register and get a little something for himself. The clerk does as he's told and buys himself a pair of jeans. If the clerk's employer later, for some reason, tries to bring criminal charges for larceny against him, then consent might be employed by the clerk's defense council.
There are some situations in which consent cannot, as a rule, be used as a defense in criminal trial. First of all, if the person who gave consent is legally incompetent in the matter at hand and has no authority to give consent, the defense probably won't stand (for example, on clerk authorizing another to take money out of the register when he really has no authority to do so). Also, consent cannot be used as a defense if the victim is incapable of making a reasonable decision because of youth, mental disability, intoxication, or some other defect. Consent is no defense if it was induced by force or duress. And, as mentioned above, consent is irrelevant in cases where the behavior is forbidden by public policy, as is often the case in the U.S. with gambling and prostitution.