ethree-common / com.virgilsecurity.android.common / EThreeCore

EThreeCore

abstract class EThreeCore

EThreeCore class simplifies work with Virgil Services to easily implement End to End Encrypted communication.

Types

PrivateKeyChangedParams

data class PrivateKeyChangedParams

Constructors

<init>

EThreeCore(identity: String, getTokenCallback: OnGetTokenCallback, keyChangedCallback: OnKeyChangedCallback?, keyPairType: KeyPairType, enableRatchet: Boolean, keyRotationInterval: TimeSpan, context: Context)

Properties

cardManager

val cardManager: CardManager

crypto

val crypto: VirgilCrypto

identity

val identity: String

keyStorage

abstract val keyStorage: KeyStorage

Functions

authDecrypt

fun authDecrypt(data: Data, user: Card? = null): Data
fun authDecrypt(data: Data, user: Card, date: Date): Data

Decrypts data and signature and verifies signature of sender.

fun authDecrypt(text: String, user: Card? = null): String
fun authDecrypt(text: String, user: Card, date: Date): String

Decrypts base64 string and signature and verifies signature of sender.

fun authDecrypt(inputStream: InputStream, outputStream: OutputStream, user: Card? = null): Unit
fun authDecrypt(inputStream: InputStream, outputStream: OutputStream, user: Card, date: Date): Unit

Decrypts stream and signature and verifies signature of sender.

authEncrypt

fun authEncrypt(data: Data, user: Card): Data

Signs then encrypts data (and signature) for user.

fun authEncrypt(text: String, user: Card): String

Signs then encrypts string (and signature) for user.

fun authEncrypt(text: String, users: FindUsersResult? = null): String
fun authEncrypt(data: Data, users: FindUsersResult? = null): Data

Signs then encrypts string (and signature) for group of users.

fun authEncrypt(inputStream: InputStream, streamSize: Int, outputStream: OutputStream, user: Card): Unit

Signs then encrypts stream and signature for user.

fun authEncrypt(inputStream: InputStream, streamSize: Int, outputStream: OutputStream, users: FindUsersResult? = null): Unit

Signs then encrypts stream and signature for users.

backupPrivateKey

fun backupPrivateKey(password: String): Completable

Encrypts the user's private key using the user's password and backs up the encrypted private key to Virgil's cloud. This enables users to log in from other devices and have access to their private key to decrypt data.

changePassword

fun changePassword(oldPassword: String, newPassword: String): Completable

Changes the password on a backed-up private key.

cleanup

fun cleanup(): Unit
  • ! WARNING ! If you call this function after register without using backupPrivateKey then you loose private key permanently, as well you won't be able to use identity that was used with that private key no more.

createGroup

fun createGroup(identifier: Data, users: FindUsersResult? = null): Result<Group>
fun createGroup(identifier: String, users: FindUsersResult? = null): Result<Group>

Creates group, saves in cloud and locally.

createRatchetChannel

fun createRatchetChannel(card: Card, name: String? = null): Result<RatchetChannel>

Creates double ratchet channel with user, saves it locally.

createTemporaryChannel

fun createTemporaryChannel(identity: String): Result<TemporaryChannel>

Creates channel with unregistered user.

decrypt

fun decrypt(data: Data, user: Card? = null): Data
fun decrypt(data: Data, user: Card, date: Date): Data

Decrypts and verifies data from users.

fun decrypt(inputStream: InputStream, outputStream: OutputStream): Unit

Decrypts encrypted stream.

fun decrypt(text: String, user: Card? = null): String
fun decrypt(text: String, user: Card, date: Date): String

Decrypts and verifies base64 string from users.

fun decrypt(base64String: String, sendersKey: VirgilPublicKey): String

Decrypts and verifies encrypted text that is in base64 String format.

fun decrypt(data: ByteArray, sendersKey: VirgilPublicKey? = null): ByteArray

Decrypts and verifies encrypted data.

deleteGroup

fun deleteGroup(identifier: Data): Completable

Deletes group from cloud (if the user is an initiator) and local storage.

fun deleteGroup(identifier: String): Completable

Deletes group from cloud and local storage.

deleteRatchetChannel

fun deleteRatchetChannel(card: Card, name: String? = null): Completable

Deletes double ratchet channel.

deleteTemporaryChannel

fun deleteTemporaryChannel(identity: String): Completable

Deletes temporary channel from the cloud (if the user is a creator) and from the local storage.

encrypt

fun encrypt(data: Data, users: FindUsersResult? = null): Data

Signs then encrypts data for group of users.

fun encrypt(inputStream: InputStream, outputStream: OutputStream, users: FindUsersResult? = null): Unit
fun encrypt(inputStream: InputStream, outputStream: OutputStream, user: Card): Unit

Encrypts data stream.

fun encrypt(text: String, users: FindUsersResult? = null): String

Signs then encrypts string for group of users.

fun encrypt(data: Data, user: Card): Data

Signs and encrypts data for user.

fun encrypt(text: String, user: Card): String

Signs and encrypts string for user.

fun encrypt(text: String, lookupResult: LookupResult): String
fun encrypt(data: ByteArray, lookupResult: LookupResult? = null): ByteArray

Signs then encrypts data for a group of users.

fun encrypt(inputStream: InputStream, outputStream: OutputStream, lookupResult: LookupResult): Unit

Encrypts data stream for a group of users.

findCachedUser

fun findCachedUser(identity: String): Result<Card?>

Retrieves card from local storage for given identity.

findCachedUsers

fun findCachedUsers(identities: List<String>, checkResult: Boolean = true): Result<FindUsersResult>

Retrieves cards from local storage for given identities.

findUser

fun findUser(identity: String, forceReload: Boolean = false): Result<Card>

Retrieves user Card from the Virgil Cloud or local storage if exists.

findUsers

fun findUsers(identities: List<String>, forceReload: Boolean = false, checkResult: Boolean = true): Result<FindUsersResult>

Retrieves users Cards from the Virgil Cloud or local storage if exists.

getGroup

fun getGroup(identifier: Data): Group?
fun getGroup(identifier: String): Group?

Returns cached local group.

getRatchetChannel

fun getRatchetChannel(card: Card, name: String? = null): RatchetChannel?

Retrieves a double ratchet channel from the local storage.

getSecureChat

fun getSecureChat(): SecureChat

getTemporaryChannel

fun getTemporaryChannel(identity: String): TemporaryChannel?

Returns cached temporary channel.

hasLocalPrivateKey

fun hasLocalPrivateKey(): Boolean

Checks whether the private key is present in the local storage of current device. Returns true if the key is present in the local key storage otherwise false.

initializeCore

fun initializeCore(): Unit

Should be called on each new instance of EThreeCore child objects. Is up to developer.

joinRatchetChannel

fun joinRatchetChannel(card: Card, name: String? = null): Result<RatchetChannel>

Joins double ratchet channel with user, saves it locally.

loadGroup

fun loadGroup(identifier: Data, card: Card): Result<Group>
fun loadGroup(identifier: String, card: Card): Result<Group>

Loads group from cloud, saves locally.

loadTemporaryChannel

fun loadTemporaryChannel(asCreator: Boolean, identity: String): Result<TemporaryChannel>

Loads temporary channel by fetching temporary key form Cloud.

lookupPublicKeys

fun lookupPublicKeys(identity: String): Result<LookupResult>

Retrieves user public key from the cloud for encryption/verification operations.

fun lookupPublicKeys(identities: List<String>): Result<LookupResult>

Retrieves user public keys from the cloud for encryption/verification operations.

register

fun register(keyPair: VirgilKeyPair? = null): Completable

Publishes the public key in Virgil's Cards Service in case no public key for current identity is published yet.

resetPrivateKeyBackup

fun resetPrivateKeyBackup(): Completable
fun resetPrivateKeyBackup(password: String): Completable

Deletes Private Key stored on Virgil's cloud. This will disable user to log in from other devices.

restorePrivateKey

fun restorePrivateKey(password: String): Completable

Pulls user's private key from the Virgil's cloud, decrypts it with Private key that is generated based on provided password and saves it to the current private keys local storage.

rotatePrivateKey

fun rotatePrivateKey(): Completable

Generates new key pair, publishes new public key for current identity and deprecating old public key, saves private key to the local storage. All data that was encrypted earlier will become undecryptable.

unregister

fun unregister(): Completable

Revokes the public key for current identity in Virgil's Cards Service. After this operation you can call EThreeCore.register again.

updateCachedUsers

fun updateCachedUsers(): Completable

Updates local cached cards.

Companion Object Functions

derivePasswordsInternal

fun derivePasswordsInternal(password: String): DerivedPasswords

Derives different passwords for login and for backup from the one provided.