3
3
[ ![ Build Status] ( https://travis-ci.com/VirgilSecurity/virgil-e3kit-kotlin.svg?branch=master )] ( https://travis-ci.com/VirgilSecurity/virgil-e3kit-kotlin )
4
4
[ ![ GitHub license] ( https://img.shields.io/badge/license-BSD%203--Clause-blue.svg )] ( https://github.com/VirgilSecurity/virgil/blob/master/LICENSE )
5
5
6
- [ Introduction] ( #introduction ) | [ SDK Features] ( #sdk-features ) | [ Install E3Kit SDK ] ( #install-e3kit-sdk ) | [ Usage] ( #usage ) | [ Samples] ( #samples ) | [ License] ( #license ) | [ Support] ( #support )
6
+ [ Introduction] ( #introduction ) | [ SDK Features] ( #sdk-features ) | [ Installation ] ( #installation ) | [ Usage Examples ] ( #usage-examples ) | [ Samples] ( #samples ) | [ License] ( #license ) | [ Docs ] ( #docs ) | [ Support] ( #support )
7
7
8
8
## Introduction
9
9
@@ -15,40 +15,27 @@ Virgil E3kit allows you to setup user encryption with multidevice support in jus
15
15
- group chats
16
16
- manage users' Public Keys
17
17
18
- ## Install E3Kit SDK
18
+ ## Installation
19
19
20
20
You can install E3Kit SDK using [ Gradle] ( https://gradle.org/ ) . Please, choose package that suits best for your needs:
21
21
22
22
| Package | Description |
23
23
| ----------| ---------|
24
24
| [ ` E3Kit ` ] ( ./ethree-kotlin ) | Standard package for Java/Kotlin with methods responses in ` callbacks ` |
25
- | [ ` E3Kit Coroutines ` ] ( ./ethree-kotlin-coroutines ) | [ Coroutines] ( https://github.com/Kotlin/kotlinx.coroutines ) package with methods responses in [ ` Deferred ` ] ( https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/ ) |
26
25
27
- ## Samples
28
-
29
- You can find the code samples for Java and Kotlin (for Kotlin-Coroutines module as well) here:
30
-
31
- | Sample type |
32
- | ----------|
33
- | [ ` Android Java ` ] ( ./samples/android-java ) |
34
- | [ ` Android Kotlin ` ] ( ./samples/android-kotlin ) |
35
- | [ ` Android Kotlin Coroutines ` ] ( ./samples/android-kotlin-coroutines ) |
36
- | [ ` Android Java Firebase ` ] ( ./samples/android-java-firebase-function ) |
37
- | [ ` Android Kotlin Firebase ` ] ( ./samples/android-kotlin-firebase-function ) |
38
26
39
- You can run any of them on an emulator to check out the example of how to initialize the SDK, register users and encrypt messages using the E3Kit.
27
+ ## Usage Examples
40
28
41
- ## Usage
29
+ #### Initialize e3kit
42
30
43
- #### Register User
44
- Use the following lines of code to authenticate a user.
31
+ In order to interact with the Virgil Cloud, the Virgil e3kit SDK must be provided with a callback that it will call to fetch the Virgil JWT from your backend for the current user.
45
32
46
33
``` kotlin
47
- var eThree: EThree ? = null
34
+ lateinit var eThree: EThree
48
35
49
36
// Listener for E3Kit initialization
50
37
val initializeListener =
51
- object : EThree . OnResultListener <EThree > {
38
+ object : OnResultListener <EThree > {
52
39
override fun onSuccess (result : EThree ) {
53
40
// Init done!
54
41
eThree = result
@@ -60,91 +47,156 @@ val initializeListener =
60
47
}
61
48
62
49
// initialize E3Kit
63
- EThree .initialize(context, virgilTokenCallback, initializeListener)
50
+ EThree .initialize(context, virgilTokenCallback).addCallback( initializeListener)
64
51
```
65
52
66
- #### Encrypt & decrypt
53
+ #### Register user
67
54
68
- Virgil E3Kit lets you use a user's Private key and his or her Public Keys to sign, then encrypt text.
55
+ Use the following lines of code to register a user:
69
56
70
57
``` kotlin
71
- var eThree: EThree ? = null
72
- var encryptedData: ByteArray? = null
73
- var encryptedText: String? = null
74
-
75
- // Listener for keys lookup Two
76
- val lookupKeysListenerTwo =
77
- object : EThree .OnResultListener <Map <String , PublicKey >> {
78
- override fun onSuccess (result : Map <String , PublicKey >) {
79
- // Decrypt data using senders public key (In this example it's E3Kit current user)
80
- val decryptedData = eThree.decrypt(encryptedData!! , result[identityInToken])
81
-
82
- // Decrypt data using senders public key (In this example it's E3Kit current user)
83
- val decryptedText = eThree.decrypt(encryptedText!! , result[identityInToken])
58
+ // TODO: Initialize e3kit
59
+
60
+ val registerListener =
61
+ object : OnCompleteListener {
62
+ override fun onSuccess () {
63
+ // User private key loaded, ready for end-to-end encrypt!
84
64
}
85
65
86
66
override fun onError (throwable : Throwable ) {
87
67
// Error handling
88
68
}
89
69
}
90
70
91
- // Listener for keys lookup
71
+ eThree.register().addCallback(registerListener)
72
+ ```
73
+ This function generates PrivateKey/PublicKey keypair, saves PrivateKey locally on device and publishes PublicKey to Virgil Cards Service.
74
+
75
+ #### Sign and encrypt data/text
76
+
77
+ This method signs the data/text with the sender's private key and encrypts the message for recipients' public key(s).
78
+
79
+ ``` kotlin
80
+ // TODO: Initialize e3kit, Register e3kit user
81
+
92
82
val lookupKeysListener =
93
- object : EThree . OnResultListener <Map < String , PublicKey > > {
94
- override fun onSuccess (result : Map < String , PublicKey > ) {
95
- val text = " I was a text, but become a byte array"
83
+ object : OnResultListener <LookupResult > {
84
+ override fun onSuccess (result : LookupResult ) {
85
+ val text = " I was text but become byte array"
96
86
val data = text.toByteArray()
97
87
98
88
// Encrypt data using user public keys
99
- encryptedData = eThree.encrypt(data, result.values.toList() )
89
+ val encryptedData = eThree.encrypt(data, result)
100
90
101
91
// Encrypt message using user public keys
102
- encryptedText = eThree.encrypt(text, result.values.toList())
103
-
104
- // E3Kit using identity that specified in Jwt provided with *virgilTokenCallback*
105
- eThree!! .lookupPublicKeys(listOf (identityInToken), lookupKeysListenerTwo)
92
+ val encryptedText = eThree.encrypt(text, result)
106
93
}
107
94
108
95
override fun onError (throwable : Throwable ) {
109
96
// Error handling
110
97
}
111
98
}
112
99
113
- // Listener for register
114
- val registerListener =
115
- object : EThree .OnCompleteListener {
116
- override fun onSuccess () {
117
- // User private key loaded!
118
- // Now we need public keys and we ready for end-to-end encrypt.
119
- eThree!! .lookupPublicKeys(listOf (" AliceUUID" , " BobUUID" ), lookupKeysListener)
100
+ // Lookup destination user public keys
101
+ eThree.lookupPublicKeys(listOf (" userUID1" , " userUID2" , " userUID3" )).addCallback(lookupKeysListener)
102
+ ```
103
+
104
+ #### Decrypt data/text and verify signature
105
+
106
+ This method decrypts the data using the recipient's private key and verifies authenticity of the decrypted data with sender's public key.
107
+
108
+ ``` kotlin
109
+ // TODO: Initialize e3kit, Register e3kit user
110
+
111
+ val lookupKeysListener =
112
+ object : OnResultListener <LookupResult > {
113
+ override fun onSuccess (result : LookupResult ) {
114
+ // Decrypt data and verify if it was really written by Bob
115
+ val decryptedData = eThree.decrypt(encryptedData, result[" bobUID" ])
116
+
117
+ // Decrypt text and verify if it was really written by Bob
118
+ val decryptedText = eThree.decrypt(encryptedText, result[" bobUID" ])
120
119
}
121
120
122
121
override fun onError (throwable : Throwable ) {
123
122
// Error handling
124
123
}
125
124
}
126
125
127
- // Listener for E3Kit initialization
128
- val initializeListener =
129
- object : EThree .OnResultListener <EThree > {
130
- override fun onSuccess (result : EThree ) {
131
- // Init done!
132
- eThree = result
133
- eThree!! .register(registerListener)
134
- }
126
+ // Lookup chat room member key
127
+ eThree.lookupPublicKeys(" bobUID" ).addCallback(lookupKeysListener)
128
+ ```
135
129
136
- override fun onError (throwable : Throwable ) {
137
- // Error handling
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
+ }
138
156
}
139
- }
140
157
141
- // initialize E3Kit
142
- EThree .initialize(context, virgilTokenCallback, initializeListener)
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
+ }
143
169
```
144
170
171
+ ## Samples
172
+
173
+ You can find the code samples for Java and Kotlin here:
174
+
175
+ | Sample type |
176
+ | ----------|
177
+ | [ ` Android Java ` ] ( ./samples/android-java ) |
178
+ | [ ` Android Kotlin ` ] ( ./samples/android-kotlin ) |
179
+ | [ ` Android Java Firebase ` ] ( ./samples/android-java-firebase-function ) |
180
+ | [ ` Android Kotlin Firebase ` ] ( ./samples/android-kotlin-firebase-function ) |
181
+ | [ ` Android Kotlin Back4App ` ] ( ./samples/android-kotlin-back4app ) |
182
+ | [ ` Android Kotlin Nexmo ` ] ( ./samples/android-kotlin-nexmo ) |
183
+
184
+ You can run any of them on an emulator to check out the example of how to initialize the SDK, register users and encrypt messages using the E3Kit.
185
+
145
186
## License
146
187
147
- This library is released under the [ 3-clause BSD License] ( LICENSE ) .
188
+ This library is released under the [ 3-clause BSD License] ( LICENSE.md ) .
189
+
190
+ ## Docs
191
+ Virgil Security has a powerful set of APIs, and the documentation below can get you started today.
192
+
193
+ * E3kit integrations with:
194
+ * [ Custom platform] [ _any_platform ]
195
+ * [ Firebase] [ _firebase ]
196
+ * [ Twilio] [ _twilio ]
197
+ * [ Nexmo] [ _nexmo ]
198
+ * [ Pubnub] [ _pubnub ]
199
+ * [ Reference API] [ _reference_api ]
148
200
149
201
## Support
150
202
Our developer support team is here to help you. Find out more information on our [ Help Center] ( https://help.virgilsecurity.com/ ) .
@@ -153,16 +205,9 @@ You can find us on [Twitter](https://twitter.com/VirgilSecurity) or send us emai
153
205
154
206
Also, get extra help from our support team on [ Slack] ( https://virgilsecurity.com/join-community ) .
155
207
156
- [ _cards_service ] : https://developer.virgilsecurity.com/docs/api-reference/card-service/v5
157
- [ _use_card ] : https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/use-card-for-crypto-operation
158
- [ _get_card ] : https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/get-card
159
- [ _search_card ] : https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/search-card
160
- [ _create_card ] : https://developer.virgilsecurity.com/docs/swift/how-to/public-key-management/v5/create-card
161
- [ _own_crypto ] : https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-own-crypto-library
162
- [ _key_storage ] : https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-key-storage
163
- [ _card_verifier ] : https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-card-verifier
164
- [ _card_manager ] : https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-card-manager
165
- [ _setup_authentication ] : https://developer.virgilsecurity.com/docs/swift/how-to/setup/v5/setup-authentication
208
+ [ _any_platform ] : https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication
209
+ [ _twilio ] : https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-twilio
210
+ [ _nexmo ] : https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-nexmo
211
+ [ _firebase ] : https://developer.virgilsecurity.com/docs/use-cases/v5/encrypted-communication-for-firebase
212
+ [ _pubnub ] : https://developer.virgilsecurity.com/docs/use-cases/v5/smart-door-lock
166
213
[ _reference_api ] : https://developer.virgilsecurity.com/docs/api-reference
167
- [ _configure_sdk ] : https://developer.virgilsecurity.com/docs/how-to#sdk-configuration
168
- [ _more_examples ] : https://developer.virgilsecurity.com/docs/how-to#public-key-management
0 commit comments