本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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)));
}
示例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);
}