6.3 Lock/Unlock Data
6.3.1 Lock Data
The lockData
method of BayunCore
class locks generic data of type byteArray with default BayunEncryptionPolicy and BayunKeyGenerationPolicy dictated by server settings.
Parameters
data : Byte Array to be locked.
success : Success block to be executed after data is successfully locked, returns locked data through key "lockedData".
failure : Failure block to be executed if locking fails, returns BayunError.
byte plainData[] = "Hello World".getBytes();
//Success Callback
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
byte[] lockedData = message.getData().getByteArray("lockedData");
Log.d(TAG, "Data locked successfully.");
return false;
}
}
//Failure Callback
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError", "");
Log.d(TAG, "Error locking data.");
return false;
}
};
bayunCore.lockData(plainData, success, failure);
6.3.2 Lock Data with Encryption Policy, Key Generation Policy
The lockData
method with encryption policy, key generation policy as parameters locks data with the encryption key dictated by the policy.
Parameters
data : Byte Array to be locked.
encryptionPolicy : BayunEncryptionPolicy determines the key for locking.
keyGenerationPolicy : BayunKeyGenerationPolicy determines the policy to generate the data encryption key.
groupId : GroupId is required if encryptionPolicy is
BayunEncryptionPolicyGroup
.success : Success block to be executed after data is successfully locked, returns locked data through key "lockedData".
failure : Failure block to be executed if locking fails, returns BayunError.
byte plainData[] = "Hello World".getBytes();;
int encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY;
int keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE;
String groupId = "<groupId>";
//Success Callback
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
byte[] lockedData = message.getData().getByteArray("lockedData");
Log.d(TAG, "Data locked successfully.");
return false;
}
}
//Failure Callback
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError", "");
Log.d(TAG, "Error locking data.");
return false;
}
};
bayunCore.lockData(plainData, encryptionPolicy, keyGenerationPolicy, groupId, success, failure);
6.3.3 Unlock Data
The unlockData
method of BayunCore
class unlocks generic data of type byteArray.
Parameters
data : Byte Array to be unlocked.
success : Success block to be executed after data is successfully unlocked, returns unlocked data through key "unlockedData".
failure : Failure block to be executed if unlocking fails, returns
BayunError
.
byte lockedData[];
//Success Callback
Handler.Callback success = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
byte[] unlockedData = message.getData().getByteArray("unlockedData");
Log.d(TAG, "Data unlocked successfully.");
return false;
}
}
//Failure Callback
Handler.Callback failure = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
String error = message.getData().getString("BayunError", "");
Log.d(TAG, "Error unlocking data.");
return false;
}
};
bayunCore.unlockData(lockedData, success, failure);
Last updated
Was this helpful?