List of usage examples for android.util Base64 NO_WRAP
int NO_WRAP
To view the source code for android.util Base64 NO_WRAP.
Click Source Link
From source file:org.starfishrespect.myconsumption.android.util.CryptoUtils.java
/** * Return a Base64 encoded String of the hash(input) (SHA 256) * @param input a String to encode/*from ww w . j av a 2 s .c o m*/ * @return a Base64 encoded String of the hash(input) (SHA 256) */ public static String sha256(String input) { MessageDigest digest = null; try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { LOGE(TAG, e.toString()); } byte[] hash = new byte[0]; if (digest != null) { try { hash = digest.digest(input.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { LOGE(TAG, e.toString()); } } return Base64.encodeToString(hash, Base64.NO_WRAP); }
From source file:Main.java
/** * Decrypt and decode ciphertext using 256-bit AES with key generated from password * * @param password used to generated key * @param base64EncodedCipherText the encrpyted message encoded with base64 * @return message in Plain text (String UTF-8) * @throws GeneralSecurityException if there's an issue decrypting *//* w ww . j av a 2 s. c o m*/ public static String decrypt(final String password, String base64EncodedCipherText) throws GeneralSecurityException { try { final SecretKeySpec key = generateKey(password); log("base64EncodedCipherText", base64EncodedCipherText); byte[] decodedCipherText = Base64.decode(base64EncodedCipherText, Base64.NO_WRAP); log("decodedCipherText", decodedCipherText); byte[] decryptedBytes = decrypt(key, ivBytes, decodedCipherText); log("decryptedBytes", decryptedBytes); String message = new String(decryptedBytes, CHARSET); log("message", message); return message; } catch (UnsupportedEncodingException e) { if (DEBUG_LOG_ENABLED) Log.e(TAG, "UnsupportedEncodingException ", e); throw new GeneralSecurityException(e); } }
From source file:Main.java
/** * Decrypt and decode ciphertext using 256-bit AES with key generated from password * * @param password used to generated key * @param base64EncodedCipherText the encrpyted message encoded with base64 * @return message in Plain text (String UTF-8) * @throws GeneralSecurityException if there's an issue decrypting *///from www. j av a 2s . com public static String decrypt(final String password, String base64EncodedCipherText) throws GeneralSecurityException { try { final SecretKeySpec key = generateKey(password); log("base64EncodedCipherText", base64EncodedCipherText); byte[] decodedCipherText = Base64.decode(base64EncodedCipherText, Base64.NO_WRAP); log("decodedCipherText", decodedCipherText); byte[] decryptedBytes = decrypt(key, ivBytes, decodedCipherText); log("decryptedBytes", decryptedBytes); String message = new String(decryptedBytes, CHARSET); log("message", message); return message; } catch (UnsupportedEncodingException e) { if (DEBUG_LOG_ENABLED) Log.e(TAG, "UnsupportedEncodingException ", e); throw new GeneralSecurityException(e); } }
From source file:Main.java
/** * Encrypt and encode message using 256-bit AES with key generated from password. * * @param password used to generated key * @param message the thing you want to encrypt assumed String UTF-8 * @return Base64 encoded CipherText/*from ww w . j a v a 2 s . c o m*/ * @throws GeneralSecurityException if problems occur during encryption */ public static String encrypt(final String password, String message) throws GeneralSecurityException { try { final SecretKeySpec key = generateKey(password); log("message", message); byte[] cipherText = encrypt(key, ivBytes, message.getBytes(CHARSET)); //NO_WRAP is important as was getting \n at the end String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP); log("Base64.NO_WRAP", encoded); return encoded; } catch (UnsupportedEncodingException e) { if (DEBUG_LOG_ENABLED) Log.e(TAG, "UnsupportedEncodingException ", e); throw new GeneralSecurityException(e); } }
From source file:Main.java
/** * Encrypt and encode message using 256-bit AES with key generated from password. * * @param password used to generated key * @param message the thing you want to encrypt assumed String UTF-8 * @return Base64 encoded CipherText/*from w w w . ja v a2 s. co m*/ * @throws GeneralSecurityException if problems occur during encryption */ public static String encrypt(final String password, String message) throws GeneralSecurityException { try { final SecretKeySpec key = generateKey(password); log("message", message); byte[] cipherText = encrypt(key, ivBytes, message.getBytes(CHARSET)); //NO_WRAP is important as was getting \n at the end String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP); log("Base64.NO_WRAP", encoded); return encoded; } catch (UnsupportedEncodingException e) { if (DEBUG_LOG_ENABLED) Log.e(TAG, "UnsupportedEncodingException ", e); throw new GeneralSecurityException(e); } }
From source file:Main.java
/** * Encrypt and encode message using 256-bit AES with key generated from password. * * * @param password used to generated key * @param message the thing you want to encrypt assumed String UTF-8 * @return Base64 encoded CipherText/*from w w w . j a v a 2s .c o m*/ * @throws GeneralSecurityException if problems occur during encryption */ public static String encrypt(final String password, String message) { log("message", message); byte[] cipherText; try { final SecretKeySpec key = generateKey(password); cipherText = encrypt(key, ivBytes, nullPadString(message).getBytes(CHARSET)); //NO_WRAP is important as was getting \n at the end String encoded = Base64.encodeToString(cipherText, Base64.NO_WRAP); log("Base64.NO_WRAP", encoded); return encoded; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (GeneralSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.appdynamics.demo.gasp.twitter.TwitterAuthentication.java
public static String getEncodedBase64Credentials() { String authEncodedBase64 = ""; try {/*from w w w . jav a2s. c o m*/ String urlEncoded = URLEncoder.encode(consumerKey, charSet) + ":" + URLEncoder.encode(consumerSecret, charSet); byte[] urlEncodedBytes = urlEncoded.getBytes(charSet); authEncodedBase64 = "Basic " + Base64.encodeToString(urlEncodedBytes, Base64.NO_WRAP); } catch (UnsupportedEncodingException e) { Log.e(TAG, "Check URL encoding", e); } return authEncodedBase64; }
From source file:org.starfishrespect.myconsumption.android.util.CryptoUtils.java
/** * Create header for basic authentication with username and password * @return HttpHeaders with basic authentication *//*from w ww . j av a2 s . c o m*/ public static HttpHeaders createHeaders(final String username, final String password) { HttpHeaders headers = new HttpHeaders() { { String auth = username + ":" + password; byte[] encodedAuth = Base64.encode(auth.getBytes(Charset.forName("US-ASCII")), Base64.NO_WRAP); String authHeader = "Basic " + new String(encodedAuth); //String authHeader = "Basic " + auth; set("Authorization", authHeader); } }; headers.add("Content-Type", "application/json"); headers.add("Accept", "*/*"); return headers; }
From source file:com.ternup.caddisfly.util.WebClient.java
private static void addCredentials(AsyncHttpClient client) { String credentials = Globals.CONNECT; String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); client.addHeader("Authorization", "Basic " + base64EncodedCredentials); }
From source file:eu.liveGov.libraries.livegovtoolkit.helper.DownloadHelper.java
private String[] getBasicAuthHeader(byte[] b64) { String s64 = Base64.encodeToString(b64, Base64.NO_WRAP); String[] s = { "Authorization", "Basic " + s64 }; return s;/*from ww w .j a va2 s.c om*/ }