Skip to content
pubscout

dtls2

0.18.1, released 2 years ago by an unverified publisher

DTLS library for Dart implemented via FFI bindings to OpenSSL.

$ flutter pub add dtls2
Source repository

What it does

Provides datagram socket encryption through a client and server implementation supporting DTLS in PKI and PSK mode via OpenSSL FFI bindings.

AI-written summary of version 0.18.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need encrypted datagram socket communication (DTLS) in a Dart or Flutter app.
  • You are targeting native platforms (Android, iOS, Windows, macOS, Linux) and can bundle or preinstall OpenSSL.

Skip it when

  • You are building for the Web, as datagram sockets and this package are not supported on web platforms.
  • You want to avoid external native dependencies like OpenSSL.

Strengths

  • Offers both client and server implementations with PKI and PSK mode support.
  • Familiar Stream-based and connection-oriented API wrapping RawDatagramSocket.

Weaknesses

  • Requires OpenSSL dynamic libraries (libssl and libcrypto) to be available or bundled on the target platform.
  • Connecting to a server currently does not work on macOS.
  • Handshake message corruption can occur when too many cipher suites are offered.

Setup

Kind
FFI (native library)
Effort
High
Code generation
No
Direct dependencies
3

Requires libssl and libcrypto from OpenSSL to be available. On Android, iOS, Windows, and macOS they often need to be bundled or installed via package managers like Homebrew or Chocolatey.

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:dtls2/dtls2.dart';

void main() async {
  final dtlsClient = await DtlsClient.bind("::", 0);
  final context = DtlsClientContext(
    verify: false,
    withTrustedRoots: false,
  );
  try {
    final connection = await dtlsClient.connect(
      InternetAddress("::1"),
      5684,
      context,
    );
    connection.send(Uint8List.fromList(utf8.encode('Hello World')));
  } finally {
    await dtlsClient.close();
  }
}

Works with

Packages commonly used together with dtls2: ones it builds on, ones built on it, and its own family.