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


Java Base32.encode方法代码示例

本文整理汇总了Java中org.apache.commons.codec.binary.Base32.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base32.encode方法的具体用法?Java Base32.encode怎么用?Java Base32.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.codec.binary.Base32的用法示例。


在下文中一共展示了Base32.encode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateSharedSecret

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
 * Generates a random secret that is 16 characters long for the client which
 * is encoded using Base32 according to RFC 3548.
 * 
 * @return Base32 encoded shared Secret
 * @throws OTPManagerException
 *             if a failure occur while generating the shared secret
 */
protected String generateSharedSecret() throws OTPManagerException {
	LOG.info("Generating shared secret...");

	int value = Constants.SECRET_BITS / 8 + Constants.SCRATCH_CODES * Constants.BYTES_PER_SCRATCH_CODE;
	byte[] sharedSecret = null;
	byte[] encodedSharedSecret = null;
	Base32 codec = new Base32();
	try {
		secureRandom = SecureRandom.getInstance(Constants.RANDOM_NUMBER_ALGORITHM);
		byte[] buffer = new byte[value];
		secureRandom.nextBytes(buffer);
		sharedSecret = Arrays.copyOf(buffer, Constants.SECRET_BITS / 8);
		encodedSharedSecret = codec.encode(sharedSecret);
		reSeed();
	} catch (Exception e) {
		LOG.error("Error while generating shared secret " + e.getMessage(), e);
		throw new OTPManagerException("Error while generating shared secret " + e.getMessage(), e);
	}
	LOG.debug("Generated shared secret successfully");
	return new String(encodedSharedSecret);
}
 
开发者ID:GSLabDev,项目名称:OTPManager,代码行数:30,代码来源:Utils.java

示例2: calculateSecretKey

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
 * Generate the secrete key for mobile devices.
 *
 * @return
 */
public static String calculateSecretKey() throws NoSuchAlgorithmException {
  byte[] secretKey = new byte[10];
  SecureRandom sha1Prng = SecureRandom.getInstance("SHA1PRNG");
  sha1Prng.nextBytes(secretKey);
  Base32 codec = new Base32();
  byte[] encodedKey = codec.encode(secretKey);
  return new String(encodedKey);
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:14,代码来源:SecurityUtils.java

示例3: generateSecretKey

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
public static String generateSecretKey() {
  byte[] buffer = new byte[SECRET_SIZE];
  secureRandom.nextBytes(buffer);
  Base32 codec = new Base32();
  byte[] secretKey = Arrays.copyOf(buffer, SECRET_SIZE);
  byte[] bEncodedKey = codec.encode(secretKey);
  String encodedKey = new String(bEncodedKey, Charsets.UTF_8);
  return encodedKey;
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:10,代码来源:TwoFactorSecretGenerator.java

示例4: encodeCheck

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
protected static char[] encodeCheck(VersionByte versionByte, byte[] data) {
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(versionByte.getValue());
        outputStream.write(data);
        byte payload[] = outputStream.toByteArray();
        byte checksum[] = StrKey.calculateChecksum(payload);
        outputStream.write(checksum);
        byte unencoded[] = outputStream.toByteArray();
        Base32 base32Codec = new Base32();
        byte[] bytesEncoded = base32Codec.encode(unencoded);

        char[] charsEncoded = new char[bytesEncoded.length];
        for (int i = 0; i < bytesEncoded.length; i++) {
            charsEncoded[i] = (char) bytesEncoded[i];
        }

        if (VersionByte.SEED == versionByte) {
            Arrays.fill(unencoded, (byte) 0);
            Arrays.fill(payload, (byte) 0);
            Arrays.fill(bytesEncoded, (byte) 0);
        }

        return charsEncoded;
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:29,代码来源:StrKey.java

示例5: generateSecretKey

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
 * Generates secret key and MIME encodes it.
 *
 * @return the MIME encoded secret key
 */
public static String generateSecretKey() {
    final int secretSize = 10;

    final byte[] buffer = new byte[secretSize];
    new Random().nextBytes(buffer);

    // Getting the key and converting it to Base32
    final Base32 codec = new Base32();
    final byte[] secretKey = Arrays.copyOf(buffer, secretSize);
    final byte[] bEncodedKey = codec.encode(secretKey);
    final String encodedKey = new String(bEncodedKey);
    return encodedKey;
}
 
开发者ID:bubblecloud,项目名称:ilves,代码行数:19,代码来源:GoogleAuthenticatorService.java

示例6: encodeBase32

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
 * Encode string for Base32.
 *
 * @param string  String
 * @param charSet CharSet
 * @return <code>String</code> Base32 string
 * @throws UnsupportedEncodingException unsupported encoding exception
 */
public static String encodeBase32(String string, String charSet) throws UnsupportedEncodingException {
	if (string == null) {
		return null;
	}
	Base32 base32 = new Base32();
	return new String(base32.encode(string.getBytes(charSet)));
}
 
开发者ID:baishui2004,项目名称:common_gui_tools,代码行数:16,代码来源:ExCodec.java

示例7: getString

import org.apache.commons.codec.binary.Base32; //导入方法依赖的package包/类
/**
 * Converts a byte array to a Base32 string.
 *
 * @param bytes The input byte array.
 * @return The output Base32 string.
 */
public static String getString(final byte[] bytes) {
	final Base32 codec = new Base32();
	final byte[] decodedBytes = codec.encode(bytes);
	return StringEncoder.getString(decodedBytes);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:12,代码来源:Base32Encoder.java


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