List of usage examples for org.bouncycastle.util.encoders Base64 encode
public static byte[] encode(byte[] data)
From source file:com.rcythr.masq.SMSActivity.java
License:Open Source License
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); try {/*w w w .jav a2 s . c om*/ KeyManager.getInstance().init(this); } catch (Exception e) { Toast.makeText(this, R.string.unknown_error, Toast.LENGTH_LONG); } setContentView(R.layout.sms_main); // Setup the List View ListView view = getListView(); registerForContextMenu(view); smsAdapter = new SMSListAdapter(this); view.setAdapter(smsAdapter); final Button send = (Button) findViewById(R.id.send); // Setup the person spinner Spinner personSpinner = (Spinner) findViewById(R.id.personSpinner); this.contactAdapter = new ContactSpinnerAdapter(this); personSpinner.setAdapter(contactAdapter); personSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { TextView displayName = (TextView) view.findViewById(R.id.display_name); TextView address = (TextView) view.findViewById(R.id.address); Spinner personSpinner = (Spinner) findViewById(R.id.personSpinner); getPreferences(MODE_PRIVATE).edit() .putString("currentSelectedAddress", ((Contact) contactAdapter.getItem(personSpinner.getSelectedItemPosition())).address) .commit(); getListView().setSelection(getListView().getCount() - 1); SMSActivity.this.displayName = displayName.getText().toString(); SMSActivity.this.currentAddress = address.getText().toString(); smsAdapter.populateSMS(SMSActivity.this.displayName, currentAddress); text.setEnabled(true); send.setEnabled(true); } public void onNothingSelected(AdapterView<?> arg0) { } }); text = (EditText) findViewById(R.id.smsBox); if (savedInstanceState != null) { text.setText(savedInstanceState.getString("textField")); } send.setOnClickListener(new OnClickListener() { public void onClick(View v) { String message = text.getText().toString(); if (message.length() > 0) { text.setText(""); // Get the proper key Key key = KeyManager.getInstance().getLookup().get(currentAddress); try { byte[] clearText = message.getBytes(); sendSMS(currentAddress, new String(Base64.encode(AES.handle(true, clearText, key.key)))); smsAdapter.populateSMS(displayName, currentAddress); } catch (InvalidCipherTextException e) { e.printStackTrace(); Toast.makeText(SMSActivity.this, R.string.error_send, Toast.LENGTH_SHORT).show(); } } } }); contactAdapter.populate(); int savedPosition = contactAdapter .getPosition(getPreferences(MODE_PRIVATE).getString("currentSelectedAddress", "")); if (savedPosition != -1) { personSpinner.setSelection(savedPosition); } receiver = new SMSBroadcastReceiver(); }
From source file:com.stg.crypto.IOObfuscator.java
License:Open Source License
private void persist() throws IOException { synchronized (this) { if (!isWritten) { byte[] keyBytes = Base64.encode(key.getEncoded()); super.out.write(keyBytes.length); super.out.write(keyBytes); super.out.write(ivBytes.length); super.out.write(ivBytes); isWritten = true;/*from w w w . j av a2 s. c o m*/ } } }
From source file:com.stg.crypto.PBEEncryptionRoutine.java
License:Open Source License
/** * //from w w w. j ava 2s.co m * convenience method for encrypting a string. * * * * @param str * Description of the Parameter * * @return String the encrypted string. * * @exception SecurityException * Description of the Exception * */ private synchronized String encrypt(byte[] salt, String str) throws SecurityException { try { init(pass, salt, iterations); String str2 = CryptoHelper .toString(Base64.encode(encryptCipher.doFinal(CryptoHelper.toByteArray(str)))); StringBuffer buf = new StringBuffer(); buf.append("["); buf.append(CryptoHelper.toString(Base64.encode(salt))); buf.append("]"); buf.append(str2); return CryptoHelper.toString(Base64.encode(CryptoHelper.toByteArray(buf.toString()))); } catch (Throwable e) { throw new SecurityException("Could not encrypt: " + e.getMessage(), e); } }
From source file:com.stgmastek.core.comm.security.PasswordEncryptionService.java
License:Open Source License
/** * Method to encrypt the password. It uses the algorithm provided in the * Constants file to encrypt the password * // w w w . j ava 2 s . c om * @see CommConstants * * @param password * The password to be encrypted * @param encodingType * The encoding type of the password supplied. * Usually it is supplied as plain text with encoding type as 'UTF-8' * @return the encrypted value as string * @throws Exception * Any exception thrown during the encryption methodology */ public synchronized String encrypt(String password, String encodingType) throws CommException { MessageDigest md = null; try { md = MessageDigest.getInstance(CommConstants.PASSWORD_ENCRYPTY_ALGO); } catch (NoSuchAlgorithmException e) { throw new CommException(e); } try { md.update(password.getBytes(encodingType)); } catch (UnsupportedEncodingException e) { throw new CommException(e); } byte raw[] = md.digest(); String hash = CryptoHelper.toString(Base64.encode(raw)); return hash; }
From source file:com.stgmastek.monitor.comm.security.PasswordEncryptionService.java
License:Open Source License
/** * Method to encrypt the password. It uses the algorithm provided in the * Constants file to encrypt the password * //w ww . j ava2s . c o m * @see CommConstants * * @param password * The password to be encrypted * @param encodingType * The encoding type of the password supplied. * Usually it is supplied as plain text with encoding type as 'UTF-8' * @return the encrypted value as string * @throws Exception * Any exception thrown during the encryption methodology */ public synchronized String encrypt(String password, String encodingType) throws CommException { MessageDigest md = null; try { md = MessageDigest.getInstance(CommConstants.PASSWORD_ENCRYPTY_ALGO); } catch (NoSuchAlgorithmException e) { throw new CommException(e); } try { md.update(password.getBytes(encodingType)); } catch (UnsupportedEncodingException e) { throw new CommException(e); } byte raw[] = md.digest(); return CryptoHelper.toString(Base64.encode(raw)); }
From source file:com.stgmastek.monitor.ws.security.PasswordEncryptionService.java
License:Open Source License
/** * Method to encrypt the password. It uses the algorithm provided in the * Constants file to encrypt the password * /*from w ww . ja v a 2s . c o m*/ * @see Constants#PASSWORD_ENCRYPTY_ALGO * * @param password * The password to be encrypted * @param encodingType * The encoding type of the password supplied. * Usually it is supplied as plain text with encoding type as 'UTF-8' * @return the encrypted value as string * @throws Exception * Any exception thrown during the encryption methodology */ public synchronized String encrypt(String password, String encodingType) throws CommException { MessageDigest md = null; try { md = MessageDigest.getInstance(Constants.PASSWORD_ENCRYPTY_ALGO); } catch (NoSuchAlgorithmException e) { throw new CommException(e); } try { md.update(password.getBytes(encodingType)); } catch (UnsupportedEncodingException e) { throw new CommException(e); } byte raw[] = md.digest(); return CryptoHelper.toString(Base64.encode(raw)); }
From source file:com.takshine.wxcrm.base.util.WxCrmRSACode.java
/** * ???//from w w w . ja v a 2s .c o m * */ public static String sign(byte[] encoderData, PrivateKey privateKey) throws Exception { Signature sig = Signature.getInstance(SIGNATURE_ALGORITHM, KEY_PROVIDER); sig.initSign(privateKey); sig.update(encoderData); return new String(Base64.encode(sig.sign())); }
From source file:com.thoughtworks.cruise.api.PipelineConfigAPI.java
License:Apache License
private Response deletePipeline(String pipeline, String user) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Authorization", "Basic " + new String(Base64.encode((user + ":badger").getBytes()))); headers.put("Accept", apiv3); headers.put("Content-Type", contentType); return RestAssured.given().headers(headers).when() .delete(Urls.urlFor("/go/api/admin/pipelines/" + pipeline)); }
From source file:com.thoughtworks.cruise.api.PluginInfoAPI.java
License:Apache License
@com.thoughtworks.gauge.Step("Verify plugin with id <pluginId> is active") public void getPluginInfo(String pluginId) throws IOException { HashMap<String, String> headers = new HashMap<String, String>(); if (state.loggedInUser() != null) { headers.put("Authorization", "Basic " + new String(Base64.encode("admin:badger".getBytes()))); }/*from www . j a v a 2 s . c o m*/ headers.put("Accept", apiVersion); Response response = RestAssured.given().headers(headers).when() .get(Urls.urlFor("/go/api/admin/plugin_info/" + pluginId)); response.then().statusCode(200).and().body("id", equalTo(pluginId)); response.then().body("status.state", equalTo("active")); }
From source file:com.thoughtworks.cruise.page.UsingPipelineDashboardAPI.java
License:Apache License
private Response getDashboard() { HashMap<String, String> headers = new HashMap<String, String>(); String user = talkToCruise.currentUserNameProvider.loggedInUser(); if (user != null) { String auth = "Basic " + new String(Base64.encode(String.format("%s:badger", user).getBytes())); headers.put("Authorization", auth); }/*from w w w .j a v a2s . c o m*/ headers.put("Accept", dashboardApiVersion); headers.put("Content-Type", "application/json"); return RestAssured.given().headers(headers).when().get(Urls.urlFor("/go/api/dashboard")); }