Use the methods in the EncodingUtil class to encode and decode URL strings, and convert strings to hexadecimal format.
| Name | Arguments | Return Type | Description |
|---|---|---|---|
| base64Decode | String inputString | Blob | Converts a Base64-encoded String to a Blob representing its normal form. |
| base64Encode | Blob inputBlob | String | Converts a Blob to an unencoded String representing its normal form. |
| convertToHex | Blob inputString | String | Returns a hexadecimal (base 16) representation of the inputString. This method can be used to compute the client response (for example, HA1 or HA2) for HTTP Digest Authentication (RFC2617). |
| urlDecode | String inputString String encodingScheme | String | Decodes a string in application/x-www-form-urlencoded format using a specific encoding scheme, for example “UTF-8.” This method uses the supplied encoding scheme to determine which characters are represented by any consecutive sequence of the from \"%xy\". For more information about the format, see The form-urlencoded Media Type in Hypertext Markup Language - 2.0. |
| urlEncode | String inputString String encodingScheme | String | Encodes a string into the application/x-www-form-urlencoded format using a specific encoding scheme, for example “UTF-8.”
This method uses the supplied encoding scheme to obtain the bytes
for unsafe characters. For more information about the format, see The form-urlencoded Media Type in Hypertext
Markup Language - 2.0. Example: String encoded = EncodingUtil.urlEncode(url, 'UTF-8'); |
@isTest private class SampleTest { static testmethod void testConvertToHex() { String myData = 'A Test String'; Blob hash = Crypto.generateDigest('SHA1',Blob.valueOf(myData)); String hexDigest = EncodingUtil.convertToHex(hash); System.debug(hexDigest); } }