diff options
Diffstat (limited to 'src/eu/siacs/conversations/utils')
-rw-r--r-- | src/eu/siacs/conversations/utils/CryptoHelper.java | 22 |
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(); + } } |