SelfSignedCertificate class
A self-signed TLS certificate for running FTPS without any setup.
Generate one with SelfSignedCertificate.generate, store certificatePem and privateKeyPem wherever your app keeps its data, and recreate it on the next start with the default constructor. Reusing the same certificate means FTP clients that trusted it once (for example FileZilla's "Always trust this certificate") don't warn again.
final cert = SelfSignedCertificate.generate();
// Save cert.certificatePem and cert.privateKeyPem, then later:
final saved = SelfSignedCertificate(
certificatePem: savedCertPem,
privateKeyPem: savedKeyPem,
);
final server = FtpServer(
2121,
fileOperations: ...,
serverType: ServerType.readAndWrite,
securityMode: FtpSecurityMode.explicit,
tlsConfig: saved.toTlsConfig(),
);
print('Certificate fingerprint: ${saved.sha256Fingerprint}');
Clients cannot verify a self-signed certificate against a certificate authority. Show sha256Fingerprint to your users so they can compare it with the fingerprint their FTP client displays on first connect.
Constructors
- SelfSignedCertificate({required String certificatePem, required String privateKeyPem})
-
Wraps a certificate and key previously created by generate (or any
other PEM-encoded certificate and matching key).
const
-
SelfSignedCertificate.generate({String commonName = 'ftp_server', List<
String> dnsNames = const ['localhost'], Duration validity = const Duration(days: 3650)}) -
Generates a new self-signed certificate with an ECDSA P-256 key.
factory
Properties
- certificatePem → String
-
The PEM-encoded certificate.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- privateKeyPem → String
-
The PEM-encoded private key that belongs to certificatePem.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sha256Fingerprint → String
-
The SHA-256 fingerprint of the certificate, as colon-separated
uppercase hex (the format
openssl x509 -fingerprint -sha256prints).no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
toTlsConfig(
) → TlsConfig - A TlsConfig that serves this certificate.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited