encode method
Encodes the input string using the codec's specific algorithm.
input
The plain text string to be encoded.
Returns the encoded string.
Throws ArgumentError if the input is invalid for this codec. Throws FormatException if encoding fails due to format issues.
Implementation
@override
String encode(String input) {
if (input.isEmpty) {
throw ArgumentError('Input cannot be empty');
}
try {
final bytes = utf8.encode(input);
return base64.encode(bytes);
} catch (e) {
throw FormatException('Failed to encode input: $e');
}
}