List of usage examples for android.util Base64 decode
public static byte[] decode(byte[] input, int flags)
From source file:no.digipost.android.authentication.ConcealAdapter.java
public String decrypt(final String cipherText) { try {/*w w w . jav a 2 s . com*/ InputStream inputStream = crypto.getCipherInputStream( new ByteArrayInputStream(Base64.decode(cipherText.getBytes(), Base64.DEFAULT)), entity); int read; byte[] buffer = new byte[1024]; ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((read = inputStream.read(buffer)) != -1) { out.write(buffer, 0, read); } inputStream.close(); out.close(); return new String(out.toByteArray()); } catch (Exception e) { Log.w("Crypto", e); } return null; }
From source file:org.kde.kdeconnect.Helpers.SecurityHelpers.RsaHelper.java
public static PublicKey getPublicKey(Context context) throws Exception { try {// w ww. j a v a 2s . c om SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); PublicKey publicKey = KeyFactory.getInstance("RSA") .generatePublic(new X509EncodedKeySpec(publicKeyBytes)); return publicKey; } catch (Exception e) { throw e; } }
From source file:se.leap.bitmaskclient.ConfigHelper.java
public static X509Certificate parseX509CertificateFromString(String certificate_string) { java.security.cert.Certificate certificate = null; CertificateFactory cf;//from w w w . java2 s .c o m try { cf = CertificateFactory.getInstance("X.509"); certificate_string = certificate_string.replaceFirst("-----BEGIN CERTIFICATE-----", "") .replaceFirst("-----END CERTIFICATE-----", "").trim(); byte[] cert_bytes = Base64.decode(certificate_string, Base64.DEFAULT); InputStream caInput = new ByteArrayInputStream(cert_bytes); try { certificate = cf.generateCertificate(caInput); System.out.println("ca=" + ((X509Certificate) certificate).getSubjectDN()); } finally { caInput.close(); } } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { return null; } catch (IllegalArgumentException e) { return null; } return (X509Certificate) certificate; }
From source file:fragments.ContextFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.context_frag, container, false); mFirstLastView = (TextView) view.findViewById(R.id.firstLastName); mNomaView = (TextView) view.findViewById(R.id.NOMA); mUserPicture = (ImageView) view.findViewById(R.id.user_image); mFirstLastView.setText(getString(R.string.welcome, App.getPrefs().getString(App.SETTINGS_FIRST_NAME, ""), App.getPrefs().getString(App.SETTINGS_LAST_NAME, ""))); mNomaView.setText(App.getPrefs().getString(App.SETTINGS_OFFICIAL_CODE, "")); String pic64 = App.getPrefs().getString(App.SETTINGS_USER_IMAGE, ""); if (!pic64.equals("")) { byte[] pic = Base64.decode(pic64, Base64.DEFAULT); mUserPicture.setImageBitmap(BitmapFactory.decodeByteArray(pic, 0, pic.length)); } else {/*ww w. ja v a2 s . c om*/ mUserPicture.setImageResource(R.drawable.nopicture); } return view; }
From source file:com.drisoftie.cwdroid.util.CredentialUtils.java
public static String deobfuscateFromBase64(byte[] key, String basePassword) { String result = null;//from ww w . j a v a 2 s .c om try { byte[] cleared = Base64.decode(basePassword, Base64.DEFAULT); byte[] decrypted = decrypt(key, cleared); result = new String(decrypted, CharEncoding.UTF_8); } catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException | UnsupportedEncodingException e) { e.printStackTrace(); } return result; }
From source file:org.gdgsp.fragment.CheckinFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); view = inflater.inflate(R.layout.fragment_checkin, container, false); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); ImageView qr = (ImageView) view.findViewById(R.id.checkin_qrcode); byte[] qrBase64 = Base64.decode(preferences.getString("qr_code", ""), Base64.DEFAULT); Bitmap qrImage = BitmapFactory.decodeByteArray(qrBase64, 0, qrBase64.length); qr.setImageBitmap(qrImage);/*ww w .j ava 2 s . co m*/ if (preferences.contains("member_profile")) { Gson gson = new Gson(); Type datasetListType = new TypeToken<Person>() { }.getType(); Person person = gson.fromJson(preferences.getString("member_profile", ""), datasetListType); TextView name = (TextView) view.findViewById(R.id.name); name.setText(person.getName()); } activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); return view; }
From source file:com.aegiswallet.objects.SMSTransactionPojo.java
public SMSTransactionPojo(String base64EncodedJSONString) { byte[] decoded = Base64.decode(base64EncodedJSONString.getBytes(), Base64.NO_WRAP); String jsonString = new String(decoded); try {//from ww w.j av a 2 s. c o m JSONObject object = new JSONObject(jsonString); this.phoneNumber = object.getString("number"); this.name = object.getString("name"); this.amount = new BigInteger(object.getString("amount")); this.btcAddress = object.getString("address"); this.timestamp = new Long(object.getString("timestamp")).longValue(); this.status = new Integer(object.getString("status")).intValue(); this.tag = object.getString("tag"); } catch (JSONException e) { Log.d(TAG, e.getMessage()); } }
From source file:net.networksaremadeofstring.cyllell.Authentication.java
private String SignHeaders(String dataToSign) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, NoSuchProviderException { PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.decode(this.PrivateKey.getBytes(), 0)); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey pk = kf.generatePrivate(spec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING"); cipher.init(Cipher.ENCRYPT_MODE, pk); byte[] EncryptedStream = new byte[cipher.getOutputSize(dataToSign.length())]; try {/* www . j a v a2 s .c o m*/ cipher.doFinal(dataToSign.getBytes(), 0, dataToSign.length(), EncryptedStream, 0); } catch (ShortBufferException e) { // TODO Auto-generated catch block e.printStackTrace(); } return Base64.encodeToString(EncryptedStream, Base64.NO_WRAP); }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.security.DefaultJSONSignerTests.java
public void testSigning() throws JSONException { JSONObject testPayload = new JSONObject(); testPayload.put("testName", "testValue"); KeyPair keyPair = generateRandomKeyPair(); String result = ""; try {//from w ww.j ava 2 s. com result = jsonSigner.sign(keyPair, testPayload); } catch (Exception e) { fail(); e.printStackTrace(); } String[] splitedValues = result.split("\\."); //check for the correct structure assertEquals(3, splitedValues.length); //check for the correct structure of the first part JSONObject firstPart = new JSONObject(new String(Base64.decode(splitedValues[0], Base64.DEFAULT))); assertEquals("RS256", firstPart.get("alg")); assertNotNull(firstPart.get("jpk")); JSONObject jpkJSONObject = new JSONObject(firstPart.getString("jpk")); //test jpk JSON assertEquals("RSA", jpkJSONObject.getString("alg")); assertNotNull(jpkJSONObject.getString("mod")); assertNotNull(jpkJSONObject.getString("exp")); //check for the correct structure of the second parts JSONObject secondPart = new JSONObject(new String(Base64.decode(splitedValues[1], Base64.DEFAULT))); assertEquals("testValue", secondPart.getString("testName")); }
From source file:org.kde.kdeconnect.Helpers.SecurityHelpers.RsaHelper.java
public static PublicKey getPublicKey(Context context, String deviceId) throws Exception { try {//from w w w . j a va 2 s . c o m SharedPreferences settings = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE); byte[] publicKeyBytes = Base64.decode(settings.getString("publicKey", ""), 0); PublicKey publicKey = KeyFactory.getInstance("RSA") .generatePublic(new X509EncodedKeySpec(publicKeyBytes)); return publicKey; } catch (Exception e) { throw e; } }