当前位置: 首页>>代码示例>>Java>>正文


Java Base32.encodeToString方法代码示例

本文整理汇总了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 ");
}
 
开发者ID:asaph,项目名称:twofactorauth,代码行数:11,代码来源:GoogleAuthenticatorDemo.java

示例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;
	}
 
开发者ID:cplutte,项目名称:bts,代码行数:56,代码来源:IDServiceImpl.java

示例3: bytesToBase32

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
public static String bytesToBase32(byte[] input) {
	Base32 b = new Base32();
	return b.encodeToString(input);
}
 
开发者ID:Sector67,项目名称:one-time-pad-library,代码行数:5,代码来源:BaseUtils.java

示例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;
}
 
开发者ID:linux-china,项目名称:google-totp-java,代码行数:18,代码来源:TOTP.java


注:本文中的org.apache.commons.codec.binary.Base32.encodeToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。