Example usage for java.lang Byte toString

List of usage examples for java.lang Byte toString

Introduction

In this page you can find the example usage for java.lang Byte toString.

Prototype

public static String toString(byte b) 

Source Link

Document

Returns a new String object representing the specified byte .

Usage

From source file:org.texai.x509.X509Utils.java

/** Creates the Texai root X.509 certificate keystore on the trusted development system.  This
 * keystore also includes a jar-signing certificate.
 *//*from  ww  w. j  a  va2  s.  c  om*/
protected static synchronized void createTexaiRootKeyStore() {
    //Preconditions
    assert !isTrustedDevelopmentSystem() || X509Utils.isJCEUnlimitedStrengthPolicy();

    if (!isTrustedDevelopmentSystem()) {
        return;
    }
    final char[] keyStorePassword = getRootKeyStorePassword();
    assert keyStorePassword != null;
    final String filePath = System.getenv("SECURITY_DIR") + "/texai-keystore.jceks";
    final File serverKeyStoreFile = new File(filePath);
    if (serverKeyStoreFile.exists()) {
        // do not overwrite it
        return;
    }
    try {
        LOGGER.info("creating Texai root key pair");
        final KeyPair rootKeyPair = generateRSAKeyPair3072();
        LOGGER.info("creating Texai root X.509 certificate");
        final X509Certificate rootX509Certificate = generateRootX509Certificate(rootKeyPair);
        LOGGER.info("root certificate...\n" + rootX509Certificate);
        final StringBuilder stringBuilder = new StringBuilder();
        for (final byte b : rootX509Certificate.getEncoded()) {
            stringBuilder.append(Byte.toString(b));
            stringBuilder.append(", ");
        }
        LOGGER.info("root certificate...\n" + rootX509Certificate);
        LOGGER.info("\nroot certificate bytes...\n" + stringBuilder.toString());
        LOGGER.info("creating Texai root X.509 certificate keystore");
        final KeyStore rootKeyStore = X509Utils.findOrCreateJceksKeyStore(filePath, keyStorePassword);
        rootKeyStore.setKeyEntry(ROOT_ALIAS, rootKeyPair.getPrivate(), keyStorePassword,
                new Certificate[] { rootX509Certificate });

        // create and store the jar-signer certificate
        LOGGER.info("creating jar-signer key pair");
        final KeyPair jarSignerKeyPair = generateRSAKeyPair2048();
        LOGGER.info("creating jar-signer X.509 certificate");
        final UUID jarSignerUUID = UUID.randomUUID();
        LOGGER.info("jar-signer UUID: " + jarSignerUUID);
        final X509Certificate jarSignerX509Certificate = generateX509Certificate(jarSignerKeyPair.getPublic(),
                rootKeyPair.getPrivate(), rootX509Certificate, jarSignerUUID, "RootCertificate"); // domainComponent
        LOGGER.info("jar-signer certificate:\n" + jarSignerX509Certificate);
        rootKeyStore.setKeyEntry(JAR_SIGNER_ALIAS, jarSignerKeyPair.getPrivate(), keyStorePassword,
                new Certificate[] { jarSignerX509Certificate, rootX509Certificate });
        rootKeyStore.store(new FileOutputStream(filePath), keyStorePassword);

        //Postconditions
        final PrivateKey privateKey = (PrivateKey) rootKeyStore.getKey(ROOT_ALIAS, keyStorePassword);
        assert privateKey != null;

    } catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException
            | SignatureException | InvalidKeyException | IOException | KeyStoreException | CertificateException
            | UnrecoverableKeyException ex) {
        throw new TexaiException(ex);
    }
}

From source file:com.sonymobile.android.media.internal.ISOBMFFParser.java

private boolean parseDataBox(BoxHeader header) {
    try {/*from w  w w.j av  a2s.c  om*/
        if (mCurrentMetaDataKey != null) {
            String metaDataValue;
            if (mCurrentMetaDataKey == KEY_DISC_NUMBER) {
                mDataSource.skipBytes(4); // skip type
                mDataSource.skipBytes(4); // skip locale
                mDataSource.skipBytes(2); // skip album id type
                                          // and album id len
                int diskNumber = mDataSource.readShort();
                mDataSource.skipBytes(2); // skip total number of disks
                metaDataValue = Integer.toString(diskNumber);
            } else {
                byte[] typefield = new byte[4];
                mDataSource.read(typefield);
                int type = typefield[0];
                int flag = (typefield[1] | typefield[2] | typefield[3]);

                Charset encoding = StandardCharsets.UTF_8;
                if (type == 2) {
                    encoding = StandardCharsets.UTF_16BE;
                }
                mDataSource.skipBytes(4); // skip locale for now
                byte[] data = new byte[(int) header.boxDataSize - 8];
                mDataSource.read(data);
                if (mCurrentMetaDataKey == KEY_TRACK_NUMBER) {
                    int trackNumber = (data[2] << 8) & 0xFF | data[3];
                    int trackTotalNumber = (data[4] << 8) & 0xFF | data[5];
                    metaDataValue = trackNumber + "/" + trackTotalNumber;
                } else if (mCurrentMetaDataKey == KEY_COMPILATION) {
                    metaDataValue = Byte.toString(data[0]);
                } else if (mCurrentMetaDataKey == KEY_GENRE) {
                    if (type == 0 && flag == 1) {
                        metaDataValue = new String(data, encoding);
                    } else {
                        int genre = data[data.length - 1];
                        genre--;
                        if (genre < 0) {
                            genre = 255;
                        }
                        metaDataValue = Integer.toString(genre);
                    }
                } else {
                    metaDataValue = new String(data, encoding);
                }
            }
            mMetaDataValues.put(mCurrentMetaDataKey, metaDataValue);
        }
    } catch (IOException e) {
        if (LOGS_ENABLED)
            Log.e(TAG, "could not read data", e);

        return false;
    }
    return true;
}

From source file:com.ibm.bi.dml.lops.compile.Dag.java

/**
 * Convert a byte array into string//w  ww  .j a v a2 s  .c om
 * 
 * @param arr
 * @return none
 */
public String getString(byte[] arr) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arr.length; i++) {
        sb.append(",");
        sb.append(Byte.toString(arr[i]));
    }

    return sb.toString();
}