I try:
import 'dart:io';
import "dart:isolate";
main() {
SecurityContext context = new SecurityContext();
var chain = Platform.script.resolve('/etc/letsencrypt/live/example.com/chain.pem').toFilePath();
var key = Platform.script.resolve('/etc/letsencrypt/live/example.com/privkey.pem').toFilePath();
context.useCertificateChain(chain);
// context.usePrivateKey(key, password: '?????');
context.usePrivateKey(key);
HttpServer.bindSecure(InternetAddress.ANY_IP_V4, 443, context).then((server) {
server.listen((HttpRequest request) {
request.response.write('Hello, world!');
request.response.close();
});
});
}
But not work! Any ideas to make this work? https://api.dartlang.org/stable/1.24.2/dart-io/HttpServer-class.html#id_bindSecure
Error Message:
Unhandled exception:
TlsException: Failure in usePrivateKeyBytes (OS Error:
KEY_VALUES_MISMATCH(x509_cmp.c:331), errno = 0)
#0 _SecurityContext.usePrivateKeyBytes (dart:io-patch/secure_socket_patch.dart:156)
#1 _SecurityContext.usePrivateKey (dart:io-patch/secure_socket_patch.dart:152)
#2 main (file:///usr/local/www/www.revisortextos.pt/bin/main.dart:2105:10)
<asynchronous suspension>
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)
I found the solution to the problem: