SASL.java

 1package eu.siacs.conversations.utils;
 2
 3import android.util.Base64;
 4
 5public class SASL {
 6	public static String plain(String username, String password) {
 7		byte[] userBytes = username.getBytes();
 8		int userLenght = userBytes.length;
 9		byte[] passwordBytes = password.getBytes();
10		byte[] saslBytes = new byte[userBytes.length+passwordBytes.length+2];
11		saslBytes[0] = 0x0;
12		for(int i = 1; i < saslBytes.length; ++i) {
13			if (i<=userLenght) {
14				saslBytes[i] = userBytes[i-1];
15			} else if (i==userLenght+1) {
16				saslBytes[i] = 0x0;
17			} else {
18				saslBytes[i] = passwordBytes[i-(userLenght+2)];
19			}
20		}
21		
22		return Base64.encodeToString(saslBytes, Base64.DEFAULT);
23	}
24}