Skip to content

Commit f53faf5

Browse files
Merge pull request #30 from VirgilSecurity/encrypt-stream-readme
Encrypt stream readme update
2 parents 1f9b127 + f1c1c4d commit f53faf5

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,47 @@ val lookupKeysListener =
127127
eThree.lookupPublicKeys("bobUID").addCallback(lookupKeysListener)
128128
```
129129

130+
#### Encrypt & decrypt large files
131+
132+
If the data that needs to be encrypted is too large for your RAM to encrypt all at once, use the following snippets to encrypt and decrypt streams.
133+
> Stream encryption doesn’t sign the data. This is why stream decryption doesn’t require VirgilPublicKey for verification unlike the general data decryption.
134+
135+
Encryption:
136+
```kotlin
137+
// TODO: initialize and register user (see EThree.initialize and EThree#register)
138+
139+
// Listener for keys lookup
140+
val lookupKeysListener =
141+
object : OnResultListener<LookupResult> {
142+
override fun onSuccess(result: LookupResult) {
143+
val assetManager = context.assets
144+
145+
assetManager.open("some_file.txt").use { inputStream ->
146+
ByteArrayOutputStream().use { outputStream ->
147+
// Encrypt input stream using user public keys and writes output to the output stream
148+
eThree.encrypt(inputStream, outputStream, result)
149+
}
150+
}
151+
}
152+
153+
override fun onError(throwable: Throwable) {
154+
// Error handling
155+
}
156+
}
157+
158+
// Lookup destination user public keys
159+
eThree.lookupPublicKeys(listOf("userUID1", "userUID2", "userUID3")).addCallback(lookupKeysListener)
160+
```
161+
162+
Decryption:
163+
```kotlin
164+
// TODO: init SDK and register users - see EThree.initialize and EThree#register
165+
ByteArrayOutputStream().use { outputStream ->
166+
// Decrypt encrypted input stream and writes output to the output stream
167+
eThree.decrypt(encryptedStream, outputStream)
168+
}
169+
```
170+
130171
## Samples
131172

132173
You can find the code samples for Java and Kotlin here:
@@ -151,10 +192,10 @@ Virgil Security has a powerful set of APIs, and the documentation below can get
151192

152193
* E3kit integrations with:
153194
* [Custom platform][_any_platform]
154-
* [Firebase][_firebase]
155-
* [Twilio][_twilio]
195+
* [Firebase][_firebase]
196+
* [Twilio][_twilio]
156197
* [Nexmo][_nexmo]
157-
* [Pubnub][_pubnub]
198+
* [Pubnub][_pubnub]
158199
* [Reference API][_reference_api]
159200

160201
## Support

0 commit comments

Comments
 (0)