5.2 Text Locking/Unlocking
5.2.1 Lock Text
The lockText
method of BayunCore
class locks text with default encryption-policy dictated by server settings.
- Parameters
String
text - Text to be locked.Callback
success - Success block to be executed after text is successfully locked, returns locked text through key "lockedText".Callback
failure - Failure block to be executed if locking fails, returns BayunError.
Java
Kotlin
String plainText = "plainText";
// Callbacks for locking text
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String lockedText = message.getData().getString("lockedText", "");
return false;
}
}
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError");
if (error.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) {
} else if (error.equalsIgnoreCase(BayunError.ERROR_ENCRYPTION_FAILED)) {
}
return false;
}
};
bayunCore.lockText(plainText, success, failure);
val plaintext = "plainText"
val encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY
val keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE
val groupId = ""
// Callbacks for locking text
val success = Handler.Callback {
val lockedText = it.data.getString("lockedText", "")
false
}
val failure = Handler.Callback {
val error = it.data.getString("BayunError")
if (error == BayunError.ERROR_INTERNET_CONNECTION) {
} else if (error == BayunError.ERROR_ENCRYPTION_FAILED) {
}
false
}
bayunCore.lockText(plaintext, encryptionPolicy, keyGenerationPolicy, groupId, success, failure)
5.2.2 Lock Text with encryption-policy
The lockText method with encryption-policy as an optional parameter locks text with the encryption key dictated by the policy.
- Parameters
String
text - Text to be locked.int
encryptionPolicy - BayunEncryptionPolicy determines the key for locking.int
keyGenerationPolicy - BayunKeyGenerationPolicy determines the policy to generate the data encryption key.String
groupId - GroupId is required if encryptionPolicy is BayunEncryptionPolicyGroup.Callback
success - Success block to be executed after text is successfully locked, returns locked text through key "lockedText".Callback
failure - Failure block to be executed if locking fails, returns BayunError.
Java
Kotlin
String plaintext = "plainText";
int encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY;
int keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE;
String groupId = "groupId";
// Callbacks for locking text
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String lockedText = message.getData().getString("lockedText", "");
return false;
}
}
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError");
if (error.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) {
} else if (error.equalsIgnoreCase(BayunError.ERROR_ENCRYPTION_FAILED)) {
}
return false;
}
};
bayunCore.lockText(plaintext, encryptionPolicy, keyGenerationPolicy, groupId, success, failure);
val plaintext = "plainText"
val encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY
val keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE
val groupId = "groupId"
// Callbacks for locking text
val success = Handler.Callback {
val lockedText = it.data.getString("lockedText", "")
false
}
val failure = Handler.Callback {
val error = it.data.getString("BayunError")
if (error == BayunError.ERROR_INTERNET_CONNECTION) {
} else if (error == BayunError.ERROR_ENCRYPTION_FAILED) {
}
false
}
bayunCore.lockText(plaintext, encryptionPolicy, keyGenerationPolicy, groupId, success, failure)
Note : If encryption-policy is other than BayunEncryptionPolicyGroup then groupId should be nil.
5.2.3 Unlock Text
The unlockText
method of BayunCore
class unlocks text.
- Parameters
String
text - Text to be unlocked.Callback
success - Success block to be executed after text is successfully unlocked, returns unlocked text through key "unlockedText".Callback
failure - Failure block to be executed if unlocking fails, returns BayunError.
Java
Kotlin
String lockedText = "lockedText";
// Callbacks for unlocking text
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String unlockedText = message.getData().getString("unlockedText", "");
return false;
}
}
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError");
if (error.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) {
} else if (error.equalsIgnoreCase(BayunError.ERROR_DECRYPTION_FAILED)) {
}
return false;
}
};
bayunCore.unlockText(lockedText, success, failure);
val lockedText = "lockedText"
// Callbacks for unlocking text
val success = Handler.Callback {
val unlockedText = it.data.getString("unlockedText", "")
false
}
val failure = Handler.Callback {
val error = it.data.getString("BayunError")
if (error == BayunError.ERROR_INTERNET_CONNECTION) {
} else if (error == BayunError.ERROR_DECRYPTION_FAILED) {
}
false
}
bayunCore.unlockText(lockedText, success, failure)