Skip to main content

boring 0.4.2 copy "boring: ^0.4.2" to clipboard
boring: ^0.4.2 copied to clipboard

Raw FFI bindings to BoringSSL, compiled and bundled through Dart Native Assets.

example/boring_example.dart

// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:ffi' as ffi;
import 'dart:typed_data';

import 'package:boring/bindings.dart' as ssl;

void main() {
  final digest = ssl.BoringArena.using((arena) {
    final input = utf8.encode('hello world');
    final md = ssl.EVP_sha256();
    final out = arena<ffi.Uint8>(ssl.EVP_MD_size(md));
    final outLen = arena<ffi.UnsignedInt>();
    final ctx = arena.register(ssl.EVP_MD_CTX_new(), ssl.EVP_MD_CTX_free);

    if (ssl.EVP_DigestInit(ctx, md) != 1 ||
        ssl.EVP_DigestUpdate(ctx, arena.copyBytes(input), input.length) != 1 ||
        ssl.EVP_DigestFinal(ctx, out, outLen) != 1) {
      throw StateError(ssl.extractBoringSslError() ?? 'SHA-256 failed');
    }
    return Uint8List.fromList(out.asTypedList(outLen.value));
  });

  final hex = digest.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
  print('SHA-256("hello world"): $hex');
}
0
likes
160
points
417
downloads

Documentation

API reference

Publisher

verified publisherlabs.dart.dev

Weekly Downloads

Raw FFI bindings to BoringSSL, compiled and bundled through Dart Native Assets.

Repository (GitHub)
View/report issues
Contributing

Topics

#crypto #ffi #security

License

BSD-3-Clause (license)

Dependencies

code_assets, crypto, hooks, logging, meta, native_toolchain_c, native_toolchain_cmake, record_use

More

Packages that depend on boring