List of usage examples for android.util Base64 DEFAULT
int DEFAULT
To view the source code for android.util Base64 DEFAULT.
Click Source Link
From source file:com.android.emailcommon.internet.MimeUtility.java
/** * Given an input stream and a transfer encoding, return a wrapped input stream for that * encoding (or the original if none is required) * @param in the input stream//from www . j av a 2 s . co m * @param contentTransferEncoding the content transfer encoding * @return a properly wrapped stream */ public static InputStream getInputStreamForContentTransferEncoding(InputStream in, String contentTransferEncoding) { if (contentTransferEncoding != null) { contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null); if ("quoted-printable".equalsIgnoreCase(contentTransferEncoding)) { in = new QuotedPrintableInputStream(in); } else if ("base64".equalsIgnoreCase(contentTransferEncoding)) { in = new Base64InputStream(in, Base64.DEFAULT); } } return in; }
From source file:com.joanzapata.PDFViewActivity.java
public void convertQrCode(String _message) { // TODO Auto-generated method stub // Find screen size WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point);/*www . j av a 2s . c o m*/ int width = point.x; int height = point.y; int smallerDimension = width < height ? width : height; smallerDimension = smallerDimension * 3 / 4; // Encode with a QR Code image QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(_message, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), smallerDimension); try { Bitmap bitmap = qrCodeEncoder.encodeAsBitmap(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); bitmapQrcode = Base64.encodeToString(byteArray, Base64.DEFAULT); } catch (WriterException e) { e.printStackTrace(); } }
From source file:com.bamobile.fdtks.util.Tools.java
public static Bitmap createBitmapFromBase64(byte[] base64Data) { Bitmap image = null;/* w w w . j a va 2 s. c om*/ try { byte[] imageData = android.util.Base64.decode(base64Data, android.util.Base64.DEFAULT); image = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); } catch (Exception ex) { ex.printStackTrace(); } return image; }
From source file:net.hiroq.rxwsc.RxWebSocketClient.java
/** * create Secret specified RFC6455.//from ww w . ja v a 2 s. c o m * * @return */ private String createSecret() { byte[] nonce = new byte[16]; for (int i = 0; i < 16; i++) { nonce[i] = (byte) (Math.random() * 256); } return Base64.encodeToString(nonce, Base64.DEFAULT).trim(); }
From source file:com.game.simple.Game3.java
private void printKeyHash() { // Add code to print out the key hash try {/*from w ww . j a v a2 s . c o m*/ PackageInfo info = getPackageManager().getPackageInfo("com.game.simple", PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { Log.d("KeyHash:", e.toString()); } catch (NoSuchAlgorithmException e) { Log.d("KeyHash:", e.toString()); } }
From source file:com.ntsync.android.sync.client.NetworkUtilities.java
private static byte[] sendAuthStep2(Context context, BigInteger clientM, String accountName, BigInteger srpA) throws UnsupportedEncodingException, ServerException, NetworkErrorException { final HttpPost post = new HttpPost(AUTH2_URI); List<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>(); values.add(new BasicNameValuePair("m", Base64.encodeToString(BigIntegers.asUnsignedByteArray(clientM), Base64.DEFAULT))); values.add(new BasicNameValuePair("srpA", Base64.encodeToString(BigIntegers.asUnsignedByteArray(srpA), Base64.DEFAULT))); HttpEntity postEntity = new UrlEncodedFormEntity(values, SyncDataHelper.DEFAULT_CHARSET_NAME); post.setHeader(postEntity.getContentEncoding()); post.setEntity(postEntity);//from ww w . ja va 2 s . c o m try { final HttpResponse resp = getHttpClient(context).execute(post, createHttpContext(accountName, null)); return getResponse(resp); } catch (IOException ex) { throw new NetworkErrorException(ex); } }
From source file:com.mytalentfolio.h_daforum.CconnectToServer.java
/** * Returns the string formatted digital signature for the data. * /*from w w w . j a v a 2s . c o m*/ * @param key * Private key for signing the data. * @param data * Data for which the signature is to be generated. * @return signed data with the provide private key. * @throws NoSuchAlgorithmException * if the specified algorithm is not available. * @throws InvalidKeyException * if privateKey is not valid. * @throws SignatureException * if this Signature instance is not initialized properly. */ private String getDataSig(PrivateKey key, String data) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { // Generate Signature For the data Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(key); signature.update(data.getBytes()); byte[] sigBytes = signature.sign(); return Base64.encodeToString(sigBytes, Base64.DEFAULT); }
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Initialize AllJoyn//w w w. j av a2 s. c o m */ private void doInit() { PeerGroupListener pgListener = new PeerGroupListener() { @Override public void foundAdvertisedName(String groupName, short transport) { Intent i = new Intent("advertisedGroupChange"); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void lostAdvertisedName(String groupName, short transport) { Intent i = new Intent("advertisedGroupChange"); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void groupLost(String groupName) { if (mGroupManager.listHostedGroups().contains(groupName) && mGroupManager.getNumPeers(groupName) == 1) { //signal was send because admin stays alone in the group //not necessary to manage this case for us Log.d(TAG, "Group destroyed event ignored"); return; } Log.d(TAG, "Group " + groupName + " was destroyed."); Intent i = new Intent("groupDestroyed"); i.putExtra("groupName", groupName); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void peerAdded(String busId, String groupName, int numParticipants) { Log.d(TAG, "peer added"); if (amIAdmin) { Log.d(TAG, "Sending salt " + Base64.encodeToString(messageEncrypter.getSalt(), Base64.DEFAULT)); Message msg = obtainMessage(BusHandler.PING); Bundle data = new Bundle(); data.putString("groupName", lastJoinedNetwork); data.putString("pingString", Base64.encodeToString(messageEncrypter.getSalt(), Base64.DEFAULT)); data.putBoolean("encrypted", false); data.putSerializable("type", Type.SALT); msg.setData(data); sendMessage(msg); } //update UI LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("participantStateUpdate")); } @Override public void peerRemoved(String peerId, String groupName, int numPeers) { //update UI Log.d(TAG, "peer left"); Intent intent = new Intent("participantStateUpdate"); intent.putExtra("action", "left"); intent.putExtra("id", peerId); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); super.peerRemoved(peerId, groupName, numPeers); } }; ArrayList<BusObjectData> busObjects = new ArrayList<BusObjectData>(); Handler mainHandler = new Handler(context.getMainLooper()); Runnable myRunnable = new Runnable() { @Override public void run() { org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(context); } }; mainHandler.post(myRunnable); busObjects.add(new BusObjectData(mSimpleService, "/SimpleService")); mGroupManager = new PeerGroupManager(SERVICE_NAME, pgListener, busObjects); mGroupManager.registerSignalHandlers(this); }
From source file:net.hiroq.rxwsc.RxWebSocketClient.java
/** * create SecretValidation specified RFC6455 * * @param secret// w ww. j a v a2 s . c o m * @return */ private String createSecretValidation(String secret) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update((secret + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").getBytes()); return Base64.encodeToString(md.digest(), Base64.DEFAULT).trim(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
From source file:com.syncedsynapse.kore2.jsonrpc.HostConnection.java
/** * Auxiliary method to open a HTTP connection. * This method calls connect() so that any errors are cathced * @param hostInfo Host info/*from ww w. jav a2s .com*/ * @return Connection set up * @throws ApiException */ private HttpURLConnection openHttpConnection(HostInfo hostInfo) throws ApiException { try { // LogUtils.LOGD(TAG, "Opening HTTP connection."); HttpURLConnection connection = (HttpURLConnection) new URL(hostInfo.getJsonRpcHttpEndpoint()) .openConnection(); connection.setRequestMethod("POST"); connection.setConnectTimeout(connectTimeout); //connection.setReadTimeout(connectTimeout); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); // http basic authorization if ((hostInfo.getUsername() != null) && !hostInfo.getUsername().isEmpty() && (hostInfo.getPassword() != null) && !hostInfo.getPassword().isEmpty()) { final String token = Base64.encodeToString( (hostInfo.getUsername() + ":" + hostInfo.getPassword()).getBytes(), Base64.DEFAULT); connection.setRequestProperty("Authorization", "Basic " + token); } // Check the connection connection.connect(); return connection; } catch (ProtocolException e) { // Won't try to catch this LogUtils.LOGE(TAG, "Got protocol exception while opening HTTP connection.", e); throw new RuntimeException(e); } catch (IOException e) { LogUtils.LOGW(TAG, "Failed to open HTTP connection.", e); throw new ApiException(ApiException.IO_EXCEPTION_WHILE_CONNECTING, e); } }