fingerprint method

String fingerprint({
  1. FingerprintType format = FingerprintType.sha256,
})

Generates a fingerprint for the RSA public key

The format determines if the fingerprint is generated using the old "md5" approach or the new "sha256" (default).

Returns a string that starts with the digest algorithm name and a colon.

Implementation

String fingerprint({FingerprintType format = FingerprintType.sha256}) {
  // See: https://coolaj86.com/articles/ssh-pubilc-key-finger(print)s/

  final data = _encodeAsChunks();
  String result;

  switch (format) {
    case FingerprintType.sha256:
      final hash = pointy_castle.SHA256Digest().process(data);
      // Base-64 without any "=" padding
      result = 'SHA256:${base64.encode(hash).replaceAll('=', '')}';
      break;

    case FingerprintType.md5:
      final hash = pointy_castle.MD5Digest().process(data);
      // Hexadecimal with colons between each byte
      result = 'MD5:${_hex(hash, separator: ':')}';
      break;
  }

  return result;
}