Databridges.NaCl.Wrapper
1.0.1
dotnet add package Databridges.NaCl.Wrapper --version 1.0.1
NuGet\Install-Package Databridges.NaCl.Wrapper -Version 1.0.1
<PackageReference Include="Databridges.NaCl.Wrapper" Version="1.0.1" />
paket add Databridges.NaCl.Wrapper --version 1.0.1
#r "nuget: Databridges.NaCl.Wrapper, 1.0.1"
// Install Databridges.NaCl.Wrapper as a Cake Addin #addin nuget:?package=Databridges.NaCl.Wrapper&version=1.0.1 // Install Databridges.NaCl.Wrapper as a Cake Tool #tool nuget:?package=Databridges.NaCl.Wrapper&version=1.0.1
Databridges C# NaCl Wrapper Library
Databridges NACL wrapper gives you a simple write and read function using implementation of the secretbox encryption standard defined in NaCl.
Databridges NACL wrapper is available for
The above wrappers can be used to send encrypted messages between them.
The Databridges NACL wrapper for C# Language binding uses
NaCl.Net
to deliver implementation of the secretbox encryption standard defined in NaCl.
Usage Overview
The following topics are covered:
- Supported platforms
- Installation.
- Initialization
- Global Configuration
- How to use with Databridges C# Library
- Change Log
- License
Supported platforms
- .NET and .NET Core - 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0
- .NET Framework 1 - 4.6.1 2, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Installation
You can use any visual studio package manager.
Install-Package Databridges.NaCl.Wrapper
Initialization
using Databridges.NaCl.Wrapper;
DataBridges_NaCl_Wrapper secretData = new DataBridges_NaCl_Wrapper();
Global Configuration
Required
The following is the required properties before using to dataBridges NaCl wrapper.
secretData.secret = '32 char alphanumeric string';
Properties | Description |
---|---|
secret |
(string) 32 char alpha numeric string. NaCl encryption secret. |
Encrypt data
To encrypt data using NaCl, databridges wrapper exposes a method named write
, This will return encrypted data if successful else it will throw error.
write()
try {
string encData = secretData.write("Your Data..");
Console.WriteLine('Encrypted: {0}', encData);
} catch (dbnwError err) {
console.log('Errors : {0} {1} {2}', err.source, err.code, err.message);
}
Parameter | Description |
---|---|
data |
(string) data to be encrypted. |
Return Values | Description |
---|---|
string |
Encrypted string. |
Exceptions:
Source | Code | Description |
---|---|---|
DBLIB_NACL_WRAPPER | INVALID_SECRET | secret is not set with the wrapper instance. |
DBLIB_NACL_WRAPPER | INVALID_DATA | If data is not passed to the function. |
DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
Decrypt data
To decrypt data using NaCl, databridges wrapper exposes a method named read
, This will return decrypted data if successful else it will throw error.
read()
try {
string decData = secretData.read("<Encrypted data.>");
console.log('Decrypted: {0}', decData);
} catch (dbnwError err) {
console.log('Errors : {0} {1} {2}', err.source, err.code, err.message);
}
Parameter | Description |
---|---|
data |
(string) data to be encrypted. |
Return Values | Description |
---|---|
string |
Encrypted string. |
Exceptions:
Source | Code | Description |
---|---|---|
DBLIB_NACL_WRAPPER | INVALID_SECRET | secret is not set with the wrapper instance. |
DBLIB_NACL_WRAPPER | INVALID_DATA | If data is not passed to the function OR data is not a valid encrypted string. |
DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
DBLIB_NACL_WRAPPER | NACL_DECRYPT_FAILED | If decryption fails due to invalid secret or manipulated data. |
How to use with Databridges C# Library
Below code shows how to integrate the NaCl wrapper with the Databridges library. After initialize you can use the wrapper library to encrypt and decrypt the data when publishing and receiving events.
// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
using dBridges;
using Databridges.NaCl.Wrapper;
dBridges.dBridges dbridge = new dBridges.dBridges();
DataBridges_NaCl_Wrapper secretData = new DataBridges_NaCl_Wrapper();
secretData.secret = "Your32 char secret.";
// .... Your databridges code comes here.
// On Subscription success event.
Action<object, object> subscribesuccess;
subscribedChannel.bind("dbridges:subscribe.success", subscribesuccess = (payload, metadata) => {
bool mflag = false;
string encData = "";
try {
// Encrypt data to publish
encData = secretData.write("Your Data..");
mflag = true;
} catch(dbnwError err) {
Console.WriteLine("Error: {0} {1} {2}", err.source, err.code, err.message);
}
if (mflag) {
subscribedChannel.publish("eventName", encData, "1");
}
});
// On payload Received event.
Action<object, object> on_eventrecd;
subscribedChannel.bind("eventName", on_eventrecd = (payload, metadata) => {
try {
// Decrypt data received in the event.
string decData = secretData.read(payload as string);
Console.WriteLine("Decrypted: {0}", decData);
} catch (dbnwError err) {
Console.WriteLine("Error: {0} {1} {2}", err.source, err.code, err.message);
}
});
Change Log
- Change log: Changes in the recent versions
License
DataBridges NaCl Wrapper is released under the MIT license.
Copyright 2022 Optomate Technologies Private Limited.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- NaCl.Net (>= 0.1.13)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 209 | 8/2/2022 |
See https://github.com/databridges-io/lib.csharp.nacl.wrapper/README.md for full details