@seald-io/react-native-accelerator
This module is a package for the Seald SDK : @seald-io/sdk
.
The @seald-io/react-native-accelerator
module exposes helper functions to greatly accelerate file encryption and decryption while using the Seald SDK in a React-Native application. Encrypting and decrypting files natively allows for much better memory management.
The package exposes four functions: encryptString
, decryptString
, encryptURI
, decryptURI
. These functions need an encryption session to be used.
Example:
import SealdSDK from '@seald-io/sdk/react-native/seald-sdk-react-native.bundle.js' // Seald SDK bundle for react native
import { encryptString, decryptString, encryptURI, decryptURI } from '@seald-io/react-native-accelerator' // accelerator functions
const seald = SealdSDK({
appId,
apiURL
})
// Creating a Seald identity
await seald.initiateIdentity({ signupJWT })
// Creating an encryption session
const encryptionSession = await sdk.createEncryptionSession({})
// Encrypt file from an URI
const encryptedFileUri = await encryptURI(URI_TO_ENCRYPT, FILENAME, encryptionSession)
// Decrypt file from an URI
const decryptedFileObject = await decryptURI(URI_TO_DECRYPT, encryptionSession)
// `decryptedFileObject.path`: URI to the decrypted file
// `decryptedFileObject.filename`: decrypted file name
// File already loaded in JS engine
const filename = 'myFilename.ext'
const fileContent = 'File data as string.'
// Encrypt file
const encryptedFile = await encryptString(fileContent, filename, encryptionSession)
// Decrypt the encrypted string:
const clearFile = await decryptString(encryptedFile, encryptionSession)
// `decryptedFileObject.fileContent`: content of the decrypted file
// `decryptedFileObject.filename`: decrypted file name
Table of contents
Type Aliases
Functions
Type Aliases
ClearFileString
Ƭ ClearFileString: Object
Type declaration
Name | Type | Description |
---|---|---|
fileContent | string | Content of the decrypted file as Base64 encoded string |
filename | string | Name of the decrypted file |
messageId | string | Id of the encryptionSession used to encrypt the file |
ClearFileURI
Ƭ ClearFileURI: Object
Type declaration
Name | Type | Description |
---|---|---|
filename | string | Name of the decrypted file |
messageId | string | Id of the encryptionSession used to encrypt the file |
path | string | URI of the decrypted file |
Functions
decryptFileAsString
▸ decryptFileAsString(fileContent
, encryptionSession
): Promise
<ClearFileString
>
Try to decrypt fileContent
, using the EncryptionSession
. Return a ClearFileString
object.
Parameters
Name | Type | Description |
---|---|---|
fileContent | string | Base64 encoded string |
encryptionSession | EncryptionSession |
Returns
Promise
<ClearFileString
>
decryptFileURI
▸ decryptFileURI(fileURI
, encryptionSession
): Promise
<ClearFileURI
>
Try to decrypt the file at the given fileURI
, using the EncryptionSession
. Return a ClearFileURI
object.
Parameters
Name | Type |
---|---|
fileURI | string |
encryptionSession | EncryptionSession |
Returns
Promise
<ClearFileURI
>
encryptFileAsString
▸ encryptFileAsString(fileContent
, filename
, encryptionSession
): Promise
<string
>
Encrypt fileContent
, with fileName
, using the EncryptionSession
, and return the encrypted file as a Base64 encoded string.
Parameters
Name | Type | Description |
---|---|---|
fileContent | string | Must be a base64 encoded string |
filename | string | |
encryptionSession | EncryptionSession |
Returns
Promise
<string
>
encryptFileURI
▸ encryptFileURI(fileURI
, filename
, encryptionSession
): Promise
<string
>
Encrypt the file at the given fileURI
, with filename
, using the EncryptionSession
. Return the URI of the encrypted file.
Parameters
Name | Type |
---|---|
fileURI | string |
filename | string |
encryptionSession | EncryptionSession |
Returns
Promise
<string
>