Bitwarden Secrets

Unoficial driver of the Bitwarden secrets Manager SDK


// ignore_for_file: unused_local_variable
import 'dart:ffi';
import 'dart:io';
import 'package:bitwarden_secrets/bitwarden_secrets.dart';

void main() {
  var accessToken = "<your access token>";
  var organizationId = "<your organization id>";

  // Create a bitwarden client
  var bws = BitwardenSecrets(organizationId, loadBitwardenLib());

  // Authroize

  // Create a project and secret
  var project = bws.projectCreate( "foo-project");
  var secret = bws.secretCreate("foo-api-Key", "xxxx-xxxx-xxxxxxx",;

  // List Secrets
  List<SecretIdentifier> secrets = bws.secretList();

  // List Projects
  List<Project> projects = bws.projectList();

  // Lookup the value of a secret with a the given key
  var fooApiKey = lookupByName(bws, "foo-api-key").value;

Secret lookupByName(BitwardenSecrets bws, String key) {
  var header = bws.secretList().singleWhere((e) => e.key == key);
  return bws.secretGet(;

DynamicLibrary loadBitwardenLib() {
  if (Platform.isWindows) {
  } else if (Platform.isAndroid || Platform.isLinux || Platform.isFuchsia) {
  } else if (Platform.isMacOS || Platform.isIOS) {
  } else {
    throw Exception("Unsupported platform: ${Platform.operatingSystem}");


This package relies on the shared library bitwarden_c which should be realeased next to your application. bitwarden_c can be built from rust source for your platform using:

# Install rust if needed
curl --proto '=https' --tlsv1.2 -sSf | sh
source $HOME/.cargo/env

# Build 
git clone
cd sdk
cargo build --release -p bitwarden-c

# Copy library to project directory
# edit extension (dll for windows, dylib for mac, etc) and <my_project_path> as needed
cp  target/release/  <my_project_path>/native/