////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== codecs



=== Purpose


Provides the facility to register encoders and decoders of textual data as methods on any object


=== Examples


[source,groovy]
----
class HTMLCodec {
    static encode = { theTarget ->
        HtmlUtils.htmlEscape(theTarget.toString())
    }
    static decode = { theTarget ->
        HtmlUtils.htmlUnescape(theTarget.toString())
    }
}
assert "&lt;p&gt;Hello World!&lt;/p&gt;" == "<p>Hello World!</p>".encodeAsHTML()
assert "<p>Hello World!</p>" == "&lt;p&gt;Hello World!&lt;/p&gt;".decodeHTML()
----


=== Description


This plugin searches for classes with names that end in the convention `Codec` and dynamically registers `encodeAs<<Codec>>` and `decode<<Codec>>` methods on `java.lang.Object` so that any data can be encoded and decoded. For more information refer to the section of link:{guidePath}security.html#codecs[Encoding and Decoding Objects] in the user guide.

Provided Codecs:

* `HTMLCodec` - encodes/decodes HTML mark-up
* `URLCodec` - encodes/decodes URLs
* `JavascriptCodec` - encodes (escapes) JavaScript
* `Base64Codec` - encodes/decodes Base64 data
* `HexCodec` - encodes a byte array or list of integers into a hex string, and decodes hex strings into byte array
* `MD5Codec` - encodes a byte array or list of integers, or the characters of a string (using default system encoding) into an MD5 digest as a hex string
* `MD5BytesCodec` - encodes a byte array or list of integers, or the characters of a string (using default system encoding) into an MD5 digest as a byte array
* `SHA1Codec` - encodes a byte array or list of integers, or the characters of a string (using default system encoding) into an SHA1 digest as a hex string
* `SHA1BytesCodec` - encodes a byte array or list of integers, or the characters of a string (using default system encoding) into an SHA1 digest as a byte array
* `SHA256Codec` - encodes a byte array or list of integers, or the characters of a string (using default system encoding) into an SHA256 digest as a hex string
* `SHA256BytesCodec` - encodes byte array or list of integers, or the characters of a string (using default system encoding) into an SHA256 digest as a byte array
