Example usage for org.apache.commons.codec.binary Base32 Base32

List of usage examples for org.apache.commons.codec.binary Base32 Base32

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base32 Base32.

Prototype

public Base32(int lineLength) 

Source Link

Usage

From source file:com.kolich.common.util.crypt.Base32Utils.java

/**
 * Encodes binary data using the Base32 algorithm but
 * does not chunk the output./*w w  w  .j a  v  a2 s  .  c  om*/
 * @param encode
 * @return
 */
public static final byte[] encodeBase32(final byte[] encode) {
    return new Base32(true).encode(encode);
}

From source file:com.kolich.common.util.crypt.Base32Utils.java

/**
 * Decodes binary data using the Base32 algorithm but
 * does not chunk the output./*from  ww  w .  j av a2 s.  co  m*/
 * @param encode
 * @return
 */
public static final byte[] decodeBase32(final byte[] decode) {
    return new Base32(true).decode(decode);
}

From source file:jenkins.branch.WorkspaceLocatorImpl.java

private static String uniqueSuffix(String name) {
    // TODO still in beta: byte[] sha256 = Hashing.sha256().hashString(name).asBytes();
    byte[] sha256;
    try {//from  w  ww .  j  a v  a2s. c  om
        sha256 = MessageDigest.getInstance("SHA-256").digest(name.getBytes(Charsets.UTF_16LE));
    } catch (NoSuchAlgorithmException x) {
        throw new AssertionError(
                "https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest",
                x);
    }
    return new Base32(0).encodeToString(sha256).replaceFirst("=+$", "");
}

From source file:nl.sidn.dnslib.message.records.dnssec.NSEC3ResourceRecord.java

@Override
public void decode(NetworkData buffer) {
    super.decode(buffer);

    short ha = buffer.readUnsignedByte();
    hashAlgorithm = DigestType.fromValue(ha);

    flags = buffer.readUnsignedByte();//w w w . j  a v  a 2 s  .com
    optout = (flags & FLAG_OPTOUT_MASK) == FLAG_OPTOUT_MASK;
    iterations = buffer.readUnsignedChar();

    saltLength = buffer.readUnsignedByte();

    salt = new byte[saltLength];
    if (saltLength > 0) {
        buffer.readBytes(salt);
    }

    hashLength = buffer.readUnsignedByte();
    byte[] hash = new byte[hashLength];
    if (hashLength > 0) {
        buffer.readBytes(hash);
    }

    Base32 b32 = new Base32(true);
    nexthashedownername = b32.encodeAsString(hash);

    int octetAvailable = rdLength - (RDATA_FIXED_FIELDS_LENGTH + saltLength + hashLength);
    new NSECTypeDecoder().decode(octetAvailable, buffer, types);

}

From source file:se.sawano.java.security.otp.CodecUtils.java

public static byte[] decodeBase32(final byte[] base32Bytes) {
    return new Base32(false).decode(base32Bytes);
}

From source file:se.sawano.java.security.otp.google.keyuri.parameters.Secret.java

private static String base32Encode(final byte[] value) {
    return new Base32(BASE32_PADDING.getBytes()[0]).encodeToString(value);
}

From source file:se.sawano.java.security.otp.TestDataHelper.java

@Test
public void should_generate_new_secret() throws Exception {
    final SharedSecret secret = new SecretService().generateSharedSecret(SHA1);

    System.out.println(new Base32(false).encodeAsString(secret.value()));

}