/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
/** * Base64-encode the given data and return a newly allocated * String with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static String encodeToString(byte[] input, int flags) { try { return new String(encode(input, flags), "US-ASCII"); } catch (UnsupportedEncodingException e) { // US-ASCII is guaranteed to be available. throw new AssertionError(e); } }
public String rsaEncrypt(InputStream keyStream, byte[] data) { try { PublicKey pubKey = readKeyFromStream(keyStream); Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); byte[] cipherData = cipher.doFinal(data); return Base64.encodeToString(cipherData, Base64.NO_WRAP); } catch (Exception e) { Log.e("rsaEncrypt", e); return ""; } }
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param str the input String to decode, which is converted to * bytes using the default charset * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(String str, int flags) { return decode(str.getBytes(), flags); }
/** * Base64-encode the given data and return a newly allocated * String with the result. * * @param input the data to encode * @param offset the position within the input array at which to * start * @param len the number of bytes of input to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static String encodeToString(byte[] input, int offset, int len, int flags) { try { return new String(encode(input, offset, len, flags), "US-ASCII"); } catch (UnsupportedEncodingException e) { // US-ASCII is guaranteed to be available. throw new AssertionError(e); } }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
public String rsaEncrypt(InputStream keyStream, byte[] data) { try { PublicKey pubKey = readKeyFromStream(keyStream); Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); byte[] cipherData = cipher.doFinal(data); return Base64.encodeToString(cipherData, Base64.NO_WRAP); } catch (Exception e) { Log.e("rsaEncrypt", e); return ""; } }