encodeHex function

String encodeHex(
  1. List<int> bytes
)

Encodes bytes as lowercase hexadecimal, two digits per byte.

This is the representation package:crypto's Digest.toString() produces and the one most systems store digests in. OpenSSL.digestHex, OpenSSL.hmacHex and EvpDigest.finishHex are this applied to their byte results; use it directly for anything else — a serial number, a key id, a fingerprint.

Implementation

String encodeHex(List<int> bytes) {
  const digits = '0123456789abcdef';
  final out = StringBuffer();
  for (final byte in bytes) {
    out.writeCharCode(digits.codeUnitAt((byte >> 4) & 0xf));
    out.writeCharCode(digits.codeUnitAt(byte & 0xf));
  }
  return out.toString();
}