toPem method
Returns the contents encoded as a PEM block.
Throws when format is KeyFormat.raw and value is not UTF-8 data.
Implementation
String toPem({String? overrideLabel}) {
final label = overrideLabel ?? pemLabel ?? 'PUBLIC KEY';
if (value is String && format == KeyFormat.pem) {
return _ensurePemLabel(value as String, label);
}
final normalized = base64Encode(toBytes());
final chunked = _chunkBase64(normalized);
return '-----BEGIN $label-----\n$chunked\n-----END $label-----';
}