aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/utils/CryptoHelper.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-15 15:13:35 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-15 15:13:35 +0100
commit8cd59bb944ed9373eb04420a32f3b7cfce0a8956 (patch)
treed25bce32c4d272358984d50241320062f1c3008a /src/eu/siacs/conversations/utils/CryptoHelper.java
parent841c6e04a9da5f8eaf00b5140da7b7934ad3cbe3 (diff)
better muc invitations. clearified the creation of ad hoc mucs with an alert dialog
Diffstat (limited to 'src/eu/siacs/conversations/utils/CryptoHelper.java')
-rw-r--r--src/eu/siacs/conversations/utils/CryptoHelper.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/utils/CryptoHelper.java b/src/eu/siacs/conversations/utils/CryptoHelper.java
index ebbbd967..550639d2 100644
--- a/src/eu/siacs/conversations/utils/CryptoHelper.java
+++ b/src/eu/siacs/conversations/utils/CryptoHelper.java
@@ -1,9 +1,14 @@
package eu.siacs.conversations.utils;
+import java.security.SecureRandom;
+import java.util.Random;
+
import android.util.Base64;
public class CryptoHelper {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
+ final protected static char[] vowels = "aeiou".toCharArray();
+ final protected static char[] consonants ="bcdfghjklmnpqrstvwxyz".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
@@ -31,4 +36,21 @@ public class CryptoHelper {
return Base64.encodeToString(saslBytes, Base64.DEFAULT);
}
+
+ public static String randomMucName() {
+ Random random = new SecureRandom();
+ return randomWord(3,random)+"."+randomWord(7,random);
+ }
+
+ protected static String randomWord(int lenght,Random random) {
+ StringBuilder builder = new StringBuilder(lenght);
+ for(int i = 0; i < lenght; ++i) {
+ if (i % 2 == 0) {
+ builder.append(consonants[random.nextInt(consonants.length)]);
+ } else {
+ builder.append(vowels[random.nextInt(vowels.length)]);
+ }
+ }
+ return builder.toString();
+ }
}