toHex method

String toHex({
  1. bool uppercase = false,
})

Returns the contents encoded as hexadecimal.

Implementation

String toHex({bool uppercase = false}) {
  String source;
  if (value is String && format == KeyFormat.hex) {
    source = value as String;
  } else {
    final bytes = toBytes();
    final buffer = StringBuffer();
    for (final b in bytes) {
      buffer.write(b.toRadixString(16).padLeft(2, '0'));
    }
    source = buffer.toString();
  }
  return uppercase ? source.toUpperCase() : source.toLowerCase();
}