BaseEncryptionService
Name | BaseEncryptionService |
---|---|
Class Path |
|
Versions | 9 10 11 |
Overview
The BaseEncryptionService
class provides encoding and decoding functionality for various encoding formats, including:
Base64
Y64 (modified Base64 for URL safety)
Hexadecimal
Fingerprint (Hex with colons)
Base32
It also supports UTF-8 encoding and allows for custom encoding configuration.
Available Functions
Encoding and Decoding Methods
protected byte[] decode(String data, String decodingFormat): byte[]
Decodes an input string based on the specified format.
Parameters:
data
(String
): The encoded string.decodingFormat
(String
): The encoding format (y64
,hex
,base64
, orplain
).
Returns:
byte[]
: The decoded byte array.
Throws:
UnsupportedEncodingException
if an unsupported format is provided.
protected String encode(byte[] bytes, String encodingFormat): String
Encodes a byte array into the specified format.
Parameters:
bytes
(byte[]
): The data to encode.encodingFormat
(String
): The target encoding format (y64
,hex
,fingerprint
,base64
).
Returns:
String
: The encoded string.
Throws:
UnsupportedEncodingException
if encoding fails.
Y64 Encoding and Decoding
public String encodeY64(byte[] bytes): String
Encodes a byte array into Y64 format (a modified Base64 for URL safety).
Parameters:
bytes
(byte[]
): The data to encode.
Returns:
String
: The Y64 encoded string.
public byte[] decodeY64(String data): byte[]
Decodes a Y64-encoded string back into bytes.
Parameters:
data
(String
): The Y64 encoded string.
Returns:
byte[]
: The decoded byte array.
Base32 Encoding and Decoding
public String encodeBase32(String data, String decodingFormat): String
Encodes a string into Base32 format after decoding it from a given format.
Parameters:
data
(String
): The input string.decodingFormat
(String
): The format of the input string (y64
,hex
,base64
, orplain
).
Returns:
String
: The Base32 encoded string.
Throws:
UnsupportedEncodingException
if an unsupported format is provided.
public String decodeBase32(String base32Text, String decodingFormat): String
Decodes a Base32-encoded string into a specified format.
Parameters:
base32Text
(String
): The Base32 encoded string.decodingFormat
(String
): The desired output format (y64
,hex
,base64
, orplain
).
Returns:
String
: The decoded value.
Throws:
UnsupportedEncodingException
if an unsupported format is provided.
Configuration Methods
public void setEncoding(String encoding): void
Sets the encoding format for the service.
Parameters:
encoding
(String
): The desired encoding format (default isUTF-8
).
Summary
The BaseEncryptionService
provides flexible encoding and decoding capabilities, supporting multiple formats such as Base64, Y64, Hex, Base32, and Fingerprint-style encoding. It is useful for cryptographic operations, secure data handling, and encoding compatibility with different formats.
This service allows for seamless conversion between different encoding formats, making it a versatile utility for security and data transformation needs.