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 NodeJS Language binding uses
tweetnacl
to deliver implementation of the secretbox encryption standard defined in NaCl.
The dataBridges NACL wrapper for NodeJS Language binding uses
tweetnacl
to deliver implementation of the secretbox encryption standard defined in NaCl.
The dataBridges NACL wrapper for Python Language binding uses
PyNaCl
to deliver implementation of the secretbox encryption standard defined in NaCl.
The dataBridges NACL wrapper for C# Language binding uses
NaCl.Net
to deliver implementation of the secretbox encryption standard defined in NaCl.
The dataBridges NACL wrapper for Java Language binding uses
io.github.instantwebp2p:tweetnacl-java
to deliver implementation of the secretbox encryption standard defined in NaCl.
The dataBridges NACL wrapper for iOS Swift Language binding uses
TweetNacl
to deliver implementation of the secretbox encryption standard defined in NaCl.
Public Repository
Supported platforms
- Node.js version 10 or newer. (The current Long Term Support (LTS) release is an ideal starting point).
Android | Firefox | Chrome | Edge |
---|---|---|---|
5.1+ | 78+ | 84+ | 99+ |
- Supports Python versions +3.6
- .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
- Minimum required : Android 5 SDK 21 (Lollipop) and above
- Swift 5.0 and above
- Deployment targets iOS 13.0 and above
Installation.
You can use NPM package manager to install the package.
Use package installer npm to install dataBridges libraries inside your application folder
Include databridges NaCl wrapper library from any of below CDN:
- jsDelivr :
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/databridges.nacl.wrapper.min.js" integrity="sha384-O34Ik4FhdcikoNSke8zZHqyXO1JjAn/Jw/pKdp/PYlVQcBB19JdPKZn0uz+wtd5t" crossorigin="anonymous"></script>
- unpkg :
<script src="https://unpkg.com/[email protected]/dist/databridges.nacl.wrapper.min.js" integrity="sha384-O34Ik4FhdcikoNSke8zZHqyXO1JjAn/Jw/pKdp/PYlVQcBB19JdPKZn0uz+wtd5t" crossorigin="anonymous"></script>
To add databridges_nacl_wrapper
package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency... and enter repository URL https://github.com/databridges-io/lib.ios.nacl.wrapper.git
.
When you enter the package dependency’s URL, choose Version package requirements, select the latest version. Xcode resolves and fetches the package dependency. Select the package’s products that you need, and add them to targets in your project.
In Xcode Project navigator, the Swift Package Dependencies section shows the newly added databridges_nacl_wrapper
package dependency. Click the disclosure triangle to view the contents of the package as it exists locally on your Mac.
Initialization
Note : dataBridges library uses socket.io for websocket protocol management.
Global Configuration
Required
The following is the required properties before using to dataBridges NaCl wrapper.
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()
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()
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 NaCl wrapper with Databridges 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
const dBridges = require('databridges-sio-client-lib');
const dbNaClWrapper = require('databridges-nacl-wrapper');
const dbridge = new dBridges();
const secretData = new dbNaClWrapper();
secretData.secret = "Your32 char secret.";
// .... Your databridges code comes here.
// On Subscription success event.
subscribeChannel.bind("dbridges:subscribe.success", (payload, metadata) => {
console.log('Channel subscribe => bind', metadata.eventname, payload, JSON.stringify(metadata));
try {
// Encrypt data to publish.
const encData = secretData.write("Your Data..");
subscribeChannel.publish("eventName", encData, "1")
} catch (err) {
console.log('Error:', err.source, err.code, err.message);
}
});
// On payload Received event.
subscribeChannel.bind("eventName", (payload, metadata) => {
console.log('eventName=> bind', metadata.eventname, payload, JSON.stringify(metadata));
try {
// Decrypt data received in the event.
const decData = secretData.read(payload);
console.log('Decrypted:', decData);
} catch (err) {
console.log('Error:', err.source, err.code, err.message);
}
});
// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
const dBridges = require('databridges-sio-client-lib');
const dbNaClWrapper = require('databridges-nacl-wrapper');
const dbridge = new dBridges();
const secretData = new dbNaClWrapper();
secretData.secret = "Your32 char secret.";
// .... Your databridges code comes here.
// On Subscription success event.
subscribeChannel.bind("dbridges:subscribe.success", (payload, metadata) => {
console.log('Channel subscribe => bind', metadata.eventname, payload, JSON.stringify(metadata));
try {
// Encrypt data to publish.
const encData = secretData.write("Your Data..");
subscribeChannel.publish("eventName", encData, "1")
} catch (err) {
console.log('Error:', err.source, err.code, err.message);
}
});
// On payload Received event.
subscribeChannel.bind("eventName", (payload, metadata) => {
console.log('eventName=> bind', metadata.eventname, payload, JSON.stringify(metadata));
try {
// Decrypt data received in the event.
const decData = secretData.read(payload);
console.log('Decrypted:', decData);
} catch (err) {
console.log('Error:', err.source, err.code, err.message);
}
});
# Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
from databridges_sio_client_lib import dBridges
from databridges_sio_client_lib.exceptions import dBError
from databridges_nacl_wrapper import databridges_nacl_wrapper
dbridge = dBridges()
secretData = databridges_nacl_wrapper()
secretData.secret = "Your32 char secret.";
# .... Your databridges code comes here.
# On Subscription success event.
async def on_SubscribeChannel(payload, metadata):
try:
# Encrypt data to publish
encData = secretData.write('Your Data..')
await self.subscribeChannel.publish('eventName', encData, 1)
except Exception as err:
print("Error: ", err.source, err.code, err.message)
self.subscribeChannel.bind("dbridges:subscribe.success", on_SubscribeChannel)
# On payload Received event.
async def on_EventReceived(payload, metadata):
try:
decData = secretData.read(payload)
print('Decrypted:', decData);
except Exception as err:
print("Error: ", err.source, err.code, err.message)
self.subscribeChannel.bind("eventName", on_EventReceived)
// 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(dnwError 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 (dnwError err) {
Console.WriteLine("Error: {0} {1} {2}", err.source, err.code, err.message);
}
});
// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
import io.databridges.databridges_nacl_wrapper.databridges_nacl_wrapper;
import io.databridges.databridges_nacl_wrapper.dbnwError;
import io.databridges:databridges_sio_java_client.dBridges;
import io.databridges.databridges-sio-java-client.exception.dBError;
databridges_nacl_wrapper secretData = new databridges_nacl_wrapper();
dBridges dbridge = new dBridges();
secretData.secret = "Your32 char secret.";
// .... Your databridges code comes here.
// On Subscription success event.
subscribeChannel.bind("dbridges:subscribe.success", new eventHandler() {
@Override
public void onEvent(Object message, metaData metadata) {
try {
String encData = secretData.write("Your Data..");
subscribeChannel.publish("eventName", encData, "1")
} catch (dbnwError err) {
Log.d("Errors", "" + err.source + "," + err.code + "," + err.message);
}
}
});
// On payload Received event.
subscribeChannel.bind("eventName", new eventHandler() {
@Override
public void onEvent(String message, metaData metadata) {
try {
String decData = secretData.read(message);
Log.d("Decrypted:", decData);
} catch (dbnwError err) {
Log.d("Errors", "" + err.source + "," + err.code + "," + err.message);
}
}
});
// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
import databridges_sio_swift_client
import databridges_nacl_wrapper
public var dbridge:databridges_sio_swift_client = databridges_sio_swift_client()
public var secretData:databridges_nacl_wrapper = databridges_nacl_wrapper()
secretData.secret = "Your32 char secret.";
// .... Your databridges code comes here.
// On Subscription success event.
try? self.subscribeChannel?.bind("dbridges:subscribe.success", {(event: Any, metadata: MetaData) in
var mflag:Bool = false
var encData:String = ""
do {
encData = try secretData.write("Your Data..");
mflag = true
} catch {
let db = error as? dbnwError
print("Error :" , db!.source , db!.code , db!.message)
}
if mflag {
try? self.subscribeChannel?.publish("eventName", encData, 1)
}
});
// On payload Received event.
try? self.subscribeChannel?.bind("eventName", {(event: Any, metadata: MetaData) in
var decData:String = ""
do {
decData = try secretData.read((event as! String))
} catch {
let db = error as? dbnwError
print("Error :", db!.source, db!.code, db!.message)
}
if !decData.isEmpty {
print("Decrypted: \(String(describing: decData))" )
}
});