encode method

  1. @override
String encode(
  1. String passphrase
)
override

Encode into text and encrypt with passphrase

Implementation

@override
String encode(String passphrase) {
  final buf = StringBuffer();

  // The algorithm can be found in the public key data
  final algorithm = BinaryRange(publicKeyBytes).nextString();

  buf
    ..write('$puttyKeyTypeTag: $algorithm\n')
    ..write('Encryption: $encryption\n')
    ..write('Comment: ${comment ?? ''}\n');
  _encodePPKLines('Public-Lines', publicKeyBytes, buf);
  _encodePPKLines('Private-Lines', privateKeyBytes, buf);
  buf.write('Private-MAC: ${_calculatePrivateMAC(algorithm, passphrase)}\n');

  // Note: PuTTYgen always produces a Comment line, even when there is no
  // comment). When there is no comment, PuTTYgen still outputs a single space
  // after the colon. This implementation produces the same results.

  return buf.toString();
}