diff options
author | pedroGitt <pedro.contreiras@amdocs.com> | 2016-10-21 19:00:46 +0200 |
---|---|---|
committer | pedroGitt <pedro.contreiras@amdocs.com> | 2016-10-21 19:00:46 +0200 |
commit | 700b02589ce61b90fb3ee4c9d0a98f7ca195a6bb (patch) | |
tree | 48b9a14d714a76eb4eb7d6bdd289d21c51223fc6 /java/android/OlmLibSdk/olm-sdk/src/main | |
parent | fb87d8feee14b36a76d8022e2b742a6c1d65d0f0 (diff) |
Add getRandomKey()
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/main')
-rw-r--r-- | java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java index 2843f0f..342d8eb 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java +++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java @@ -20,10 +20,14 @@ import android.text.TextUtils; import android.util.Log; import java.io.Serializable; +import java.util.Random; -public class OlmUtility implements Serializable { +public class OlmUtility { private static final String LOG_TAG = "OlmUtility"; + public static final int RANDOM_KEY_SIZE = 32; + public static final int RANDOM_RANGE = 256; + /** raw pointer value returned by JNI. * this value uniquely identifies this utility instance. **/ @@ -128,9 +132,17 @@ public class OlmUtility implements Serializable { private native String sha256Jni(String aMessage); - // TODO missing API: initWithSerializedData - // TODO missing API: serializeDataWithKey - // TODO missing API: initWithCoder - // TODO missing API: encodeWithCoder + public static String getRandomKey() { + String keyRetValue; + Random rand = new Random(); + StringBuilder strBuilder = new StringBuilder(); + + for(int i = 0; i< RANDOM_KEY_SIZE; i++) { + strBuilder.append(rand.nextInt(RANDOM_RANGE)); + } + keyRetValue = strBuilder.toString(); + + return keyRetValue; + } } |