Chrysalis and cocoon are two physical objects that are made in the same phase of a butterfly or moth's life, however, a chrysalis refers to the casing that a butterfly makes when it transforms, whereas a cocoon is a woven case made by a moth during this stage to protect itself. The materials that a cocoon and a chrysalis are made of are also different.
The chrysalis stage is also called the pupa stage, and is a phase of a butterfly or moth's life between the larva stage, when the butterfly or moth is a caterpillar, and the adult stage. During this stage, butterflies form a chrysalis by secreting a hard protein shell around themselves. Moths on the other hand spin their cocoons out of a silk-like material. Butterflies can also secrete silk, but only enough to adhere themselves to the surface they make their chrysalis on.
Depending on the species, butterflies and moths remain in the pupa stage for varying amounts of time. This stage can take weeks, months or even years, and emergence from this stage can also be caused by seasonal changes. When emerging, a butterfly or moth secretes a special liquid called cocoonase to weaken the chrysalis or cocoon and claws or cuts its way out.