本文整理汇总了Java中org.apache.commons.codec.binary.Base32.encodeToString方法的典型用法代码示例。如果您正苦于以下问题:Java Base32.encodeToString方法的具体用法?Java Base32.encodeToString怎么用?Java Base32.encodeToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.binary.Base32
的用法示例。
在下文中一共展示了Base32.encodeToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRandomSecretKey
import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
public static String getRandomSecretKey() {
SecureRandom random = new SecureRandom();
byte[] bytes = new byte[20];
random.nextBytes(bytes);
Base32 base32 = new Base32();
String secretKey = base32.encodeToString(bytes);
// make the secret key more human-readable by lower-casing and
// inserting spaces between each group of 4 characters
return secretKey.toLowerCase().replaceAll("(.{4})(?=.{4})", "$1 ");
}
示例2: createId
import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
public String createId(String dbCollection)
{
Map<String, BTSProjectDBCollection> map = loadProjectDBCollectionMap();
BTSProjectDBCollection coll = null;
if (map != null && map.containsKey(dbCollection))
{
if (map.get(dbCollection).getProperty(BTSConstants.DB_COLLECTION_PROP_RESERVE_ID) != null
&& map.get(dbCollection).getProperty(BTSConstants.DB_COLLECTION_PROP_RESERVE_ID).equals("true"))
{
coll = map.get(dbCollection);
}
}
String id = null;
if (coll != null)
{
id = findReservedId(coll);
}
if (id != null)
{
return id;
}
now = Calendar.getInstance();
id = new Long(now.getTimeInMillis()).toString();
BTSUser user = (BTSUser) eclipseCtx.get("currentUser");
if (user != null)
{
id += user.get_id().substring(5, 15);
}
if (btsUUID != null && btsUUID.length() > 10)
{
id += btsUUID.substring(5, 10);
}
while (id.length() < 32)
{
id += new Long(now.getTimeInMillis()).toString();
}
String uuid = id.substring(0, 32).replaceAll(
PATTERN,
GROUPS);
// creating UUID
UUID uid = UUID.fromString(uuid);
id = uid.randomUUID().toString();
id = id.replace("-", "");
// encode Base32 to reduce size
Base32 base32 = new Base32();
byte[] array = DatatypeConverter.parseHexBinary(id);
id = base32.encodeToString(array);
id = id.replace("-", "Q");
id = id.replace("_", "W");
id = id.replace("=", "");
// System.out.println(id);
return id;
}
示例3: bytesToBase32
import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
public static String bytesToBase32(byte[] input) {
Base32 b = new Base32();
return b.encodeToString(input);
}
示例4: getAuthUrl
import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
* get totp auth url
*
* @param user user, mainly email
* @param issuer issuer
* @param plaintSecret plain secret
* @return auth url
* @throws Exception
*/
public static String getAuthUrl(String user, String issuer, String plaintSecret) throws Exception {
Base32 base32 = new Base32();
String secret = base32.encodeToString(plaintSecret.getBytes());
if (secret.contains("=")) {
secret = secret.substring(0, secret.indexOf("="));
}
return "otpauth://totp/" + user + "?secret=" + secret + "&issuer=" + issuer;
}