For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


JSONStore security utilities Android examples

Learn about JSONStore security utilities Android examples.


Encryption and decryption

String password = "HelloPassword"; String salt = SecurityUtils.getRandomString(32); int iterations = 10000; String key = SecurityUtils.generateKey(password, salt, iterations); String originalText = "Hello World!"; JSONObject encryptedObject = SecurityUtils.encrypt(key, originalText); // Deciphered text will be the same as the original text. String decipheredText = SecurityUtils.decrypt(key, encryptedObject);


Encode and decode base64

import android.util.Base64; String originalText = "Hello World"; byte[] base64Encoded = Base64.encode(text.getBytes("UTF-8"), Base64.DEFAULT); String encodedText = new String(base64Encoded, "UTF-8"); byte[] base64Decoded = Base64.decode(text.getBytes("UTF-8"), Base64.DEFAULT); // Decoded text will be the same as the original text. String decodedText = new String(base64Decoded, "UTF-8");


Get remote random

Context context; // This is the current Activity's context. int byteLength = 32; // Listener calls the callback functions after it gets the response from the server. WLRequestListener listener = new WLRequestListener(){ @Override public void onSuccess(WLResponse wlResponse) { // Implement the success handler. } @Override public void onFailure(WLFailResponse wlFailResponse) { // Implement the failure handler. } }; SecurityUtils.getRandomStringFromServer(byteLength, context, listener);


Get local random

int byteLength = 32; String randomString = SecurityUtils.getRandomString(byteLength);

Parent topic: JSONStore security utilities examples