diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/CryptoHelper.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java index d34823d86..e16d0d012 100644 --- a/src/main/java/de/pixart/messenger/utils/CryptoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/CryptoHelper.java @@ -35,15 +35,15 @@ import rocks.xmpp.addr.Jid; public final class CryptoHelper { + public static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"); + final public static byte[] ONE = new byte[]{0, 0, 0, 1}; + private static final char[] CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz123456789+-/#$!?".toCharArray(); + private static final int PW_LENGTH = 10; private static final char[] VOWELS = "aeiou".toCharArray(); private static final char[] CONSONANTS = "bcfghjklmnpqrstvwxyz".toCharArray(); - public static final String FILETRANSFER = "?FILETRANSFERv1:"; private final static char[] hexArray = "0123456789abcdef".toCharArray(); - public static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"); - final public static byte[] ONE = new byte[]{0, 0, 0, 1}; - public static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { @@ -54,6 +54,14 @@ public final class CryptoHelper { return new String(hexChars); } + public static String createPassword(SecureRandom random) { + StringBuilder builder = new StringBuilder(PW_LENGTH); + for (int i = 0; i < PW_LENGTH; ++i) { + builder.append(CHARS[random.nextInt(CHARS.length - 1)]); + } + return builder.toString(); + } + public static String pronounceable(SecureRandom random) { char[] output = new char[random.nextInt(4) * 2 + 5]; boolean vowel = random.nextBoolean(); @@ -293,4 +301,4 @@ public final class CryptoHelper { final String u = url.toLowerCase(); return !u.contains(" ") && (u.startsWith("https://") || u.startsWith("http://") || u.startsWith("p1s3://")) && u.endsWith(".pgp"); } -} +}
\ No newline at end of file |