Git Product home page Git Product logo

skycoder42 / libsodium_dart_bindings Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 6.0 11.46 MB

Dart bindings for libsodium, supporting both the VM and JS without flutter dependencies.

Home Page: https://pub.dev/packages/sodium

License: BSD 3-Clause "New" or "Revised" License

Dart 95.95% Swift 0.08% CMake 1.52% C++ 1.74% C 0.12% HTML 0.15% CSS 0.01% Ruby 0.33% Kotlin 0.03% Objective-C 0.01% Java 0.02% Dockerfile 0.02% Shell 0.02%
flutter dart libsodium libsodium-bindings sodium cross-platform windows linux macos android

libsodium_dart_bindings's Introduction

libsodium_dart_bindings

Continous Integration for package sodium Pub Version

Continous Integration for package sodium_libs Pub Version

This repository is a multi package repository for dart bindings of libsodium. It consists of the following packages. Please check the READMEs of the specific packages for more details on them.

If you just landed here and don't know where to start, simply read the sodium README, as that is the primary package of this repository.

  • sodium: Dart bindings for libsodium, supporting both the VM and JS without flutter dependencies.
  • sodium_libs: Flutter companion package to sodium that provides the low-level libsodium binaries for easy use.

libsodium_dart_bindings's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libsodium_dart_bindings's Issues

please update ffi

Please, update ffi. The old version blocks updates. The new version have no backward incompatibility.
Thank you!

Request for SecretStream encryption/decryption example

I am playing around XChaCha20 crypto.secretStream. I've managed to successfully run encryption and decryption of two chunks, but only if it's executed from the same code block (no data serialization in between the encryption and decryption).
In my example (like in most cases), I need to operate on raw data. That means that after encryption I need to clearly get the: nonce, ciphertext and tag. Conversely having raw nonce, ciphertext and tag I need to initialize the decryption process. This is where I am failing.

Code that fails (for simplicity I am using only single chunk):

  test('libsodiumXChaCha20IntegritySerializedSimple', () async {
    final libsodium = DynamicLibrary.open('/usr/lib/x86_64-linux-gnu/libsodium.so'); // dpkg -L libsodium-dev | grep "\.so"
    final sodium = await SodiumInit.init(libsodium);

    final plaintextChunk1 = "encrypted_test_contents1";

    final unwrappedKey = AesKwRfc3394.unwrap(encryptedKey, base64MasterKey);
    final secureKey = SecureKey.fromList(sodium, Uint8List.fromList(unwrappedKey));

    final encryptedChunk1 = sodium.crypto.secretStream.push(messageStream: Stream.fromIterable([Uint8List.fromList(utf8.encode(plaintextChunk1))]), key: secureKey);
    final encryptedChunk1Raw =  (await encryptedChunk1.toList()).first;

    final chunk1CipherMsg = SecretStreamCipherMessage(encryptedChunk1Raw);

    // decrypt

    final decryptedChunk1 = sodium.crypto.secretStream.pullEx(cipherStream: Stream.fromIterable([chunk1CipherMsg]), key: secureKey);

    final l1 = await decryptedChunk1.toList();
    final decodedChunk1 = utf8.decode(l1.first.message);

    assert(plaintextChunk1 == decodedChunk1);
  });

It fails on:

final l1 = await decryptedChunk1.toList();

with:

cipher stream was closed before the final push message was received

Code that seem to work and does the encrypt/decrypt in one go.

test('libsodiumXChaCha20Integrity', () async {
    final libsodium = DynamicLibrary.open('/usr/lib/x86_64-linux-gnu/libsodium.so'); // dpkg -L libsodium-dev | grep "\.so"
    final sodium = await SodiumInit.init(libsodium);

    final plaintextChunk1 = "encrypted_test_contents1";
    final plaintextChunk2 = "somethingThatWouldLikeTo";

    final unwrappedKey = AesKwRfc3394.unwrap(encryptedKey, base64MasterKey);
    final secureKey = SecureKey.fromList(sodium, Uint8List.fromList(unwrappedKey));

    final encryptedChunk1 = sodium.crypto.secretStream.push(messageStream: Stream.fromIterable([Uint8List.fromList(utf8.encode(plaintextChunk1))]), key: secureKey);

    final chunk2Msg = SecretStreamPlainMessage(Uint8List.fromList(utf8.encode(plaintextChunk2)), tag: SecretStreamMessageTag.finalPush);
    final encryptedChunk2 = sodium.crypto.secretStream.pushEx(messageStream: Stream.fromIterable([chunk2Msg]), key: secureKey);

   // decrypt

    final decryptedChunk1 = sodium.crypto.secretStream.pull(cipherStream: encryptedChunk1, key: secureKey);
    final decryptedChunk2 = sodium.crypto.secretStream.pullEx(cipherStream: encryptedChunk2, key: secureKey);

    final l1 = await decryptedChunk1.toList();
    final decodedChunk1 = utf8.decode(l1.first);

    final l2 = await decryptedChunk2.toList();
    final decodedChunk2 = utf8.decode(l2.first.message);

    assert(plaintextChunk1 == decodedChunk1);
    assert(plaintextChunk2 == decodedChunk2);
  });

EDIT: I've came across this example which I am going to play with: #11 (comment)

iOS: Failed to lookup symbol 'sodium_init'

Hello,
I'm experiencing the following issue when testing my app through TestFlight on a real device:

ArgumentError
Invalid argument(s): Failed to lookup symbol 'sodium_init': dlsym(RTLD_DEFAULT, sodium_init): symbol not found

Further details:

  • sodium_libs 2.2.1+5
  • Flutter 3.22.1
  • iPhone 8
  • iOS 16.7.8

I've set Runner -> Build Settings -> Deployment -> Strip Style to Non-Global Symbols, but to no avail.

The annoying part is that it works properly on the Simulator, same for Android on a real device.

Any thoughts?

SecretStream Push method

I just have a question: from my understanding of the docs, the provided push method of the SecretStream API handles all the tag and header creation and ordering, right? So, instead of deciding for each chunk whether this is a final message or not (and hence set the respective tag), I only have to provide a stream of Uint8List, right? Or is there anything else I need to consider? I'm trying to implement this: https://libsodium.gitbook.io/doc/secret-key_cryptography/secretstream#example-stream-encryption

Thanks a lot!

EDIT:
I tried:

Future<Map<String, String>> encryptFile(File sourceFile, File targetFile) async {
    IOSink sink = targetFile.openWrite();
    SecureKey key = _sodium.crypto.secretStream.keygen();
    _sodium.crypto.secretStream.push(messageStream: sourceFile.openRead().map<Uint8List>((chunk) => Uint8List.fromList(chunk)), key: key).listen(
          (event) => sink.add(event),
        );

    debugPrint("DONE");
    return {"key": hex.encode(key.extractBytes())};
  }

  decryptFile(File sourceFile, File targetFile, SecureKey key) async {
    IOSink sink = targetFile.openWrite();
    _sodium.crypto.secretStream.pull(cipherStream: sourceFile.openRead().map<Uint8List>((chunk) => Uint8List.fromList(chunk)), key: key).listen(
          (event) => debugPrint("CHUNK"),
        );
  }

but I always receive: Unhandled Exception: cipher stream was closed before the final push message was received.

What do I wrong?

Fails to build on Fedora

Hello,
I just tried to build an app I made in Flutter using your package sodium_libs and through some experimenting I found out that there seem to be issues when linking the sodium binary to the app:

Launching lib/main.dart on Linux in debug mode...
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Building Linux application...                                           
Exception: Build process failed

When trying to use -v it gives the exact same output and through a little bit of trial and error I eventually landed on your package being the reason for my app not building. I have no idea if this is an issue on my part or if I'm just being stupid, and if I am I'm sorry.

I already tried the following things:
Building with pkg-config (as said in the docs, didn't work)
I also checked if I have libsodium installed and it was there

How I replicated the bug
Basically all you have to do is create a new flutter project on Fedora and then add this package as the only dependency, at that point it won't build.

How update flutter_sodium 0.2.0 to sodium_libs?

My code:
/// Generates a random secret key and a corresponding public key.
var receiver=Sodium.cryptoBoxKeypair();
In sodium_libs doesn't have cryptoboxKeypair() method.
I'm trying use this: var receiver = Box.keyPair();
But is error: Instance member 'keyPair' can't be accessed using static access.
How can I generate random secret key and a a corresponding public key in sodium_libs?

Regenerate Sign KeyPair

Hello,

I am currently using the package for a 3D-Secure procedure. For this reason, I need to generate the SecureKey once for the lifetime of the app and then store it in the secure storage to release payments via the generated public key.

My current procedure is to create a random string as a seed to create a keyPair. Is there a better way to do this?

final seed = SecureKey.fromList(
  _sodium,
  Uint8List.fromList(data.codeUnits),
);

final keyPair = _sign.seedKeyPair(seed);

final secureKey = keyPair.secretKey;

Because sign.keyPair() always generates a complete new keyPair and for the detached method I need the secretKey object.

How to create a shared secret using Scalarmult?

Hello,
I have a problem with creating a shared secret, previously I was using ScalarMult for this, but I see the constructor now is private, how it is possible to do now?
Also, would it be possible to get your assistance/contacts please?
Thanks!

Implement crypto_stream_xchacha20

I'm interested in non-authenticated XChaCha20, for use with SIV.

@timshadel

This issue was extracted from #5, as the remaining tasks of that issue have all been completed with Version 2.0.0.

How to test?

When I try to write a test for my flutter up and intialize sodium there, it always complains:

ArgumentError (Invalid argument(s): Failed to lookup symbol 'sodium_init': dlsym(RTLD_DEFAULT, sodium_init): symbol not found)

How can I write a test and use sodium there? The "failing" line is:

_sodium = await SodiumInit.init();

Thanks a lot!

Upgrade to latest freezed version

Hi,

Unfortunately, the package blocks me from updating Freezed and analyzer in my app and thus the latest language features of dart 2.17 cannot be used.

Would it be possible to update the dependencies? I can also assist with this.

Secret stream state initialization; Continue interrupted upload of encrypted stream;

Secret stream documentation: https://libsodium.gitbook.io/doc/secret-key_cryptography/secretstream says:
"Since the length of the stream is not limited, it can also be used to encrypt files regardless of their size."

In order to reliably upload multiple GB over the HTTP it is safe to assume that this will take a while, connection might drop or even system might crash over the period of hours / days.

I am looking for a way to start secretstream encryption from last saved checkpoint before failure took place.

In C API I believe that state is kept externally and can always be restored if needed e.g.

crypto_secretstream_xchacha20poly1305_state state;
crypto_secretstream_xchacha20poly1305_init_push(&state, header, key);

In Dart bindings I've found comment in the: secret_stream.dart:

  /// Unlike the C API, which requires manual state management etc., this API
  /// combines all the required parts into a single, simple dart stream. As a
  /// first step, crypto_secretstream_xchacha20poly1305_init_push is used to
  /// generate the stream state from the [key] and the created header is sent
  /// as the first message of the returned [SecretExStream].

Is it possible to initialize state manually with libsodium_dart_bindings in order to start encryption stream from a certain point?

FFI failure or SodiumInit timing problem?

Released a new Flutter based Android and iOS app and they both crash with this error:

Error: NoSuchMethodError: Class 'GenericHashFFI' has no instance of method 'call'.
Receiver: Instance of 'GenericHashFFI'
Tried calling: call(message: Uint8Array, outLen:32)

Both apps worked fine when building and running the app using development tools. We also released them using version 1.1.1 back in late September and they were fine.

Could this be related to the 1.2.0 change?

1.2.0
Added
• Support for 32bit architectures by generalizing the native FFI bindings (#7)
Changed
• Set minimum required dart SDK version to 2.14
• Updated dependencies
• Upgraded dart ffi language bindings
• Use new callable workflows for workflow simplification
Fixed
• Fix formatting and linter issues with the newer dart SDK & dependencies

My other thought is that perhaps there is some sort of timing issue from the init to the first Sodium call - which in our case is sodium.crypto.genericHash. I am doing an await on SodiumInit.init() but perhaps I'm missing something? Is there a way to know that the initialization has completed?

Thanks!

sodium.js - Cannot read properties of undefined (reading 'then')

Hello,
I'm trying to initialize a sodium object but when I run my application with flutter run -d chrome, I get the following error :

TypeError: Cannot read properties of undefined (reading 'then')
at http://localhost:44957/sodium.js:1:771173
at http://localhost:44957/sodium.js:1:771205

I am using Flutter.
I'm using plateform web

How I call the init function :

import 'package:sodium_libs/sodium_libs.dart';
final sodium = await SodiumInit.init();

If I suround with try catch, nothing is caught.

my pubspec.yaml :

name: my_app
description: A new Flutter project.
publish_to: "none"
version: 1.0.0+1

environment:
  sdk: ">=2.17.6 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  sodium_libs: ^1.2.4+1
  sodium: ^1.2.3

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true

Is there anything I am doing wrong ?
Thank you for help

LateInitializationError occurs when used in isolate

E/flutter (24445): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: LateInitializationError: Field '_instance@2084288322' has not been initialized.
E/flutter (24445): #0 SodiumPlatform._instance (package:sodium_libs/src/sodium_platform.dart)
E/flutter (24445): #1 SodiumPlatform.instance (package:sodium_libs/src/sodium_platform.dart:21:41)

sodium_libs version: 1.2.0
flutter version: 2.8

used like this:


await Executor().execute(
    arg1: str1,
    fun1: (String demo) async {
      // this is an isolate
      final sodium = await CustomSodiumInit.init();   // this line occurs LateInitializationError 
      final encData = sodium.crypto.secretBox.easy(...);
      // ...
    },
  );

CustomSodiumInit code:


// ......
static Future<sodium.Sodium> init({
    @Deprecated('initNative is no longer required and will be ignored.')
        bool initNative = true,
  }) =>
      _instanceLock.synchronized(() async {
        if (_instance != null) {
          return _instance!;
        }
        
        // Comment out this line or an exception(Unhandled Exception: UI actions are only available on root isolate) will occur
        // WidgetsFlutterBinding.ensureInitialized();
        _instance = await SodiumPlatform.instance.loadSodium();
        if (!kReleaseMode) {
          if (_instance!.version < _expectedVersion) {
            // ignore: avoid_print
            print(
              'WARNING: The embedded libsodium is outdated! '
              'Expected $_expectedVersion, but was ${_instance!.version}}. '
              '${SodiumPlatform.instance.updateHint}',
            );
          }
        }
        return _instance!;
      });

sodium_libs version 1.1.1 will work, but 1.2.0 not

Speed of sodium.crypto.secretBox.easy() etc...

Hello. I am trying this library after trying other crypto libraries and I heard that using libsodium native libraries would be faster than dart software implementations like PointyCastle. But I believe I'm getting the same speeds with this library and wanted to check whether I was doing something wrong or not. I am just creating a 100mb Uint8List and encrypting it and it is taking about 12 seconds with sodium.crypto.secretBox.easy() and sodium.crypto.aead.encrypt(). I have a gist of my sample code...

https://gist.github.com/hootyjeremy/54f43cb5c5886999a7fa255c13be10f9

Am I running these correctly? Are these two methods using the libsodium.dll native C code? Could you confirm if you're getting similar speeds (I know it will vary by machine) for these 100mb arrays? I was hoping to have them encrypt 100mb within 1 second which is what other software that encrypts with Chacha or AES will do.

Sodium.runIsolated breaking flutter run build

@Skycoder42 I see you updated the pub.dev package to sodium 2.1.0 about 4 hours ago. Now it's breaking builds =(

NOTE:

sodium_libs is failing Pass static analysis due to Sodium.runIsolated:

https://pub.dev/packages/sodium_libs/score

Directory output:

Looks like sodium-2.1.0 is a new directory created today.

~/.pub-cache/hosted/pub.dev/

Mar  3 18:06 sodium-2.0.1
Mar  8 10:18 sodium-2.1.0
Mar  3 18:06 sodium_libs-2.0.0

Console output:

../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_ios.dart:8:7: Error: The non-abstract class '_SodiumIos' is missing implementations for these members:
 - Sodium.runIsolated
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _SodiumIos implements Sodium {
      ^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart:69:13: Context: 'Sodium.runIsolated' is defined here.
  Future<T> runIsolated<T>(
            ^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_ios.dart:43:7: Error: The non-abstract class '_SodiumSumoIos' is missing implementations for these members:
 - Sodium.runIsolated
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _SodiumSumoIos extends _SodiumIos implements SodiumSumo {
      ^^^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart:69:13: Context: 'Sodium.runIsolated' is defined here.
  Future<T> runIsolated<T>(
            ^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_macos.dart:8:7: Error: The non-abstract class '_SodiumMacos' is missing implementations for these members:
 - Sodium.runIsolated
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _SodiumMacos implements Sodium {
      ^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart:69:13: Context: 'Sodium.runIsolated' is defined here.
  Future<T> runIsolated<T>(
            ^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_macos.dart:43:7: Error: The non-abstract class '_SodiumSumoMacos' is missing implementations for these members:
 - Sodium.runIsolated
Try to either
 - provide an implementation,
 - inherit an implementation from a superclass or mixin,
 - mark the class as abstract, or
 - provide a 'noSuchMethod' implementation.

class _SodiumSumoMacos extends _SodiumMacos implements SodiumSumo {
      ^^^^^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart:69:13: Context: 'Sodium.runIsolated' is defined here.
  Future<T> runIsolated<T>(
            ^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_ios.dart:33:15: Error: The method 'secureHandle' isn't defined for the class 'Sodium'.
 - 'Sodium' is from 'package:sodium/src/api/sodium.dart' ('../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart').
Try correcting the name to the name of an existing method, or defining a method named 'secureHandle'.
      _sodium.secureHandle(nativeHandle);
              ^^^^^^^^^^^^
../../../../.pub-cache/hosted/pub.dev/sodium_libs-2.0.0/lib/src/platforms/sodium_macos.dart:33:15: Error: The method 'secureHandle' isn't defined for the class 'Sodium'.
 - 'Sodium' is from 'package:sodium/src/api/sodium.dart' ('../../../../.pub-cache/hosted/pub.dev/sodium-2.1.0/lib/src/api/sodium.dart').
Try correcting the name to the name of an existing method, or defining a method named 'secureHandle'.
      _sodium.secureHandle(nativeHandle);
              ^^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

Cannot build on Windows

I have setup a fresh Windows 11 virtual machine with Visual Studio 2022 CE and Flutter 2.10.
Everything works fine, but as soon as I try to build the windows app, it says:

CMake Error at flutter/ephemeral/.plugin_symlinks/sodium_libs/windows/CMakeLists.txt:19 (execute_process):
  execute_process error getting child return code: %1 ist keine zulässige
  Win32-Anwendung

Any ideas, what the problem could be?

The failing command in the CMakeLists.txt is:

execute_process(COMMAND "${DART}" run
                "${CMAKE_CURRENT_SOURCE_DIR}/../libsodium_version.dart"
                OUTPUT_VARIABLE LIBSODIUM_VERSION_JSON
                COMMAND_ERROR_IS_FATAL ANY

Thanks and best regards!

How does one use AES-GCM?

I've just realized that this package doesn't have API bindings to AES-GCM.

#/lib/src/api/aead.dart
/// Currently, only the crypto_aead_xchacha20poly1305_ietf_* APIs have been
/// implemented.

I've noticed relevant functions inside of: bindings/libsodium.ffi.dart, e.g. crypto_aead_aes256gcm_encrypt

Is there any shortcut I could perhaps use with FFI directly to call relevant libsodium functions and get the AES-GCM decrypt/encrypt? I need to say that I didn't have chance to work with FFI directly, but it seems now it is the moment.

Any hints are very much appreciated.

Full build for Android version

It seems that the dynamic libraries for Android (which are downloaded from this repository) don't contain certain methods which are necessary for certain applications. For example, in order to integrate libopaque into a Flutter app, it requires Ristretto255 to be present in libsodium, i.e., it needs to be compiled with the LIBSODIUM_FULL_BUILD environment variable set.

The presence of a "full build" can be checked by using nm -gD libsodium.so | grep ristretto and seeing if any such symbols are present.
Would it be possible to integrate these full builds for Android into sodium_libs, instead of using minimal builds?

build failure: libsodium.so not found on latest update

@Skycoder42

SUMMARY

Build fails on latest sodium update. Failed to load dynamic library 'libsodium.so'

CONSOLE OUTPUT

E/flutter ( 4835): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'libsodium.so': dlopen failed: library "libsodium.so" not found
E/flutter ( 4835): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11)
E/flutter ( 4835): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22)
E/flutter ( 4835): #2      SodiumAndroid.loadSodium.<anonymous closure> (package:sodium_libs/src/platforms/sodium_android.dart:16)
E/flutter ( 4835): #3      SodiumInit.init2.<anonymous closure> (package:sodium/src/ffi/sodium_ffi_init.dart:59)
E/flutter ( 4835): #4      SodiumInit.initFromSodiumFFI2.<anonymous closure> (package:sodium/src/ffi/sodium_ffi_init.dart:81)
E/flutter ( 4835): #5      SodiumFFI.fromFactory (package:sodium/src/ffi/api/sodium_ffi.dart:49)
E/flutter ( 4835): #6      SodiumInit.initFromSodiumFFI2 (package:sodium/src/ffi/sodium_ffi_init.dart:80)
E/flutter ( 4835): #7      SodiumInit.init2 (package:sodium/src/ffi/sodium_ffi_init.dart:58)
E/flutter ( 4835): #8      SodiumAndroid.loadSodium (package:sodium_libs/src/platforms/sodium_android.dart:15)
E/flutter ( 4835): #9      SodiumInit.init.<anonymous closure> (package:sodium_libs/src/sodium_init.dart:35)
E/flutter ( 4835): #10     BasicLock.synchronized (package:synchronized/src/basic_lock.dart:31)
E/flutter ( 4835): #11     SodiumInit.init (package:sodium_libs/src/sodium_init.dart:30)
E/flutter ( 4835): #12     SodiumHelper.init (package:changefly/src/domain/sodium_helper.dart:10)
E/flutter ( 4835): #13     preSetup (package:changefly/src/main.dart:98)
E/flutter ( 4835): #14     main (package:changefly/src/main.dart:71)
E/flutter ( 4835): <asynchronous suspension>
E/flutter ( 4835): 

Application finished.

OVERRIDE pubspec.yaml:

  sodium_libs: 2.0.0
  sodium: 2.0.1

Implement cryptoSignEd25519SkToSeed (crypto_sign_ed25519_sk_to_seed)

The flutter_sodium package, which has since been replaced by the soldium_libs, does offer implementations for this, but I couldn't locate the same function implementation here.

Check out this link for an implementation of the flutter_sodium crypto_sign_ed25519_sk_to_seed function.

Here is also the official doc link for libsodium.
https://libsodium.gitbook.io/doc/public-key_cryptography/public-key_signatures#extracting-the-seed-and-the-public-key-from-the-secret-key

I'd like crypto_stream_xchacha20 and Point*scalar multiplication to be available

I'm interested in non-authenticated XChaCha20, for use with SIV. I'm also interested in something a bit lower-level than the kx API. I know both of these fall under the advanced tab, and that those items aren't yet implemented. I don't mind putting together a couple PRs, but I'd like some guidance on how you'd like to have the Advanced items organized (under which objects do they go, etc.) or if you'd rather not offer them at all yet.

Cannot read properties of undefined (reading 'then')

Hi
When i try to initialize a sodium object (final sodium = await SodiumInit.init();) i get the error mentioned in the title. I tried it out with the provided example and get the same error.
What am i doing wrong?

Can't generate keys on Android

I try to generate a secure key by using:
await sodium.crypto.secretBox.keygen(); in Flutter (using sodium_libs: ^1.1.1).
This works fine on iOS, but fails with an error on Android:
RangeError (RangeError (count): Invalid value: Not greater than or equal to 0: -5365866809427754976)

How can I fix this?

Thanks a lot!

Create `Sodium.runIsolated` method to easily run computation heavy cryptographic operations in an isolate

Hi. I want to ask a question.
Do we need to run sodium functions (such as _sodium.crypto.genericHash.call() or _sodium.crypto.secretBox.easy()) behind an isolate? Because I am pretty sure that these jobs (hashing, encrypting, ...) take a long time (on a large amount of data) and might lead to frame drop.

If the answer is yes, can we do that in the library (under the hood)? Because at the moment, functions are defined sync. We can make them async and return a Future to be able to run an isolate.

Use chacha20poly1305 instead of xchacha20poly1305_ietf

Hey, is it possible to use chacha20poly1305 instead of xchacha20poly1305_ietf? I get a UDP stream from a web server with a nonce of 8 byte and i can't decrypt it because xchacha20poly1305_ietf needs a nonce of 24 bytes.

How to set SecureKey manually?

I have my own secretKey (as Uint8List) - how can I use it in soda.crypto.box.easy? I get an error "Unhandled Exception: type 'Uint8List' is not a subtype of type 'SecureKey' in type cast" and I don't know how to convert Uint8List to SecureKey

Flutter_test Failed to lookup symbol 'sodium_init'

Hello,
I'm back to you with a little problem that I'm not able to understand/solve.
I would like to perform unit tests on functions using sodium_libs, but I encounter a problem when launching the tests.

Here is an example of usage I do

import 'package:sodium_libs/sodium_libs.dart';

Future<T> myFunction() async {
  final sodium = await SodiumInit.init();

  //do something using sodium.crypto.box.keyPair()
  //return res;
}

And how i try to perform test :

import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:client/crypt/myLibUsingSodium.dart';

void main() {
  test('test myFunction()', () async {
    var res = await myFunction().then((value) {
    return value;
    });
    // assert(something); 
  });
}

here is the error log when I start test:

Invalid argument(s): Failed to lookup symbol 'sodium_init': 
/home/userName/snap/flutter/common/flutter/bin/cache/artifacts/engine/linux-x64/flutter_tester: 
undefined symbol: sodium_init

dart:ffi                                                   DynamicLibrary.lookup
package:sodium/src/ffi/bindings/libsodium.ffi.dart 66:54   LibSodiumFFI._sodium_initPtr
package:sodium/src/ffi/bindings/libsodium.ffi.dart         LibSodiumFFI._sodium_initPtr
package:sodium/src/ffi/bindings/libsodium.ffi.dart 67:29   LibSodiumFFI._sodium_init
package:sodium/src/ffi/bindings/libsodium.ffi.dart         LibSodiumFFI._sodium_init
package:sodium/src/ffi/bindings/libsodium.ffi.dart 62:12   LibSodiumFFI.sodium_init
package:sodium/src/ffi/sodium_ffi_init.dart 44:27          SodiumInit.initFromSodiumFFI
package:sodium/src/ffi/sodium_ffi_init.dart 27:7           SodiumInit.init
package:sodium_libs/src/platforms/sodium_linux.dart 14:69  SodiumLinux.loadSodium
package:sodium_libs/src/sodium_init.dart 45:51             SodiumInit.init.<fn>
package:synchronized/src/basic_lock.dart 31:24             BasicLock.synchronized
package:sodium_libs/src/sodium_init.dart 40:21             SodiumInit.init
package:client/crypt/myLibUsingSodium.dart 36:35           myFunction
test/myFunction_test.dart 10:40                            main.<fn>

I don't know how to solve this problem, or if I can solve it.
Could you help me please ?

best regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.