Example usage for java.lang String getBytes

List of usage examples for java.lang String getBytes

Introduction

In this page you can find the example usage for java.lang String getBytes.

Prototype

public byte[] getBytes() 

Source Link

Document

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Usage

From source file:D_common.E_ncript.java

public static byte[] makeAESKey(String keyStr) {
    byte[] key = keyStr.getBytes();
    byte[] key2 = new byte[KEYLENGTH];
    for (int i = 0; i < KEYLENGTH; i++) {
        if (i < key.length) {
            key2[i] = key[i];//  w  w  w . j av a2 s. c  om
        } else {
            key2[i] = 0;
        }
    }
    return key2;
}

From source file:Main.java

public static String encodeStringToString(String dataStr, int Base64Flags) {
    byte[] data = dataStr.getBytes();
    return encodeToString(data);
}

From source file:Base64Converter.java

public static String encode(String s) {
    return encode(s.getBytes());
}

From source file:com.contentful.vault.compiler.SqliteUtils.java

static String hashForId(String id) {
    return Base64.encodeBase64String(id.getBytes()).replaceAll("=", "").toLowerCase();
}

From source file:Main.java

private static byte[] make_kb(String strKey, int size) {
    byte[] kb = new byte[size];
    byte[] bytes = strKey.getBytes();
    System.arraycopy(bytes, 0, kb, 0, bytes.length > size ? size : bytes.length);
    return kb;//from   w  w  w. java  2 s . c om
}

From source file:Main.java

/**
 * Generate HTTP Basic Authorization Header
 * //from  w  ww.  j  av  a  2 s  .  c  om
 * @param username username
 * @param password password
 * @return Generated header
 */
public static String getPasswordDigest(String username, String password) {
    String authString = username + ":" + password;
    return Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);
}

From source file:Main.java

public static boolean cache(Context context, String file, String data, int mode) {
    return cache(context, file, data.getBytes(), mode);
}

From source file:Main.java

public static String getB64Auth(String login, String pass) {
    String source = login + ":" + pass;
    String ret = "Basic " + Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP);
    return ret;/*  w w  w .  j  a  va 2  s.c  om*/
}

From source file:Main.java

public static String getCnASCII(String str) {
    StringBuffer sb = new StringBuffer();
    byte[] strByte = str.getBytes();
    for (int i = 0; i < strByte.length; i++) {
        sb.append(Integer.toHexString(strByte[i] & 0xff));
    }// w w w  . j  ava  2s . c om
    return sb.toString();
}

From source file:Main.java

public static String utf8Encode(String str, String defultReturn) {
    if (!isEmpty(str) && str.getBytes().length != str.length()) {
        try {/*from  w  ww  . ja v a  2 s  .  c  om*/
            return URLEncoder.encode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return defultReturn;
        }
    }
    return str;
}