@Override public void onReceive(Context c, Intent i) { type = i.getStringExtra("type"); prefs = PreferenceManager.getDefaultSharedPreferences(c); ctx = c; mHandler = new Handler(); message = i.getStringExtra("message"); day = i.getStringExtra("day"); date = i.getBooleanExtra("dated", false); Log.d( "ULTIMATE SCHEDULER", "RECEIVED " + type + ":" + message + ". " + Boolean.toString(date) + " : " + day); if (type.equals("tweet")) { username = i.getStringExtra("username"); mentions = i.getStringExtra("mentions").replaceAll(",", ""); sendTweet(); } else if (type.equals("sms")) { if (!Character.isDigit(i.getStringExtra("recipient").charAt(0))) { recipient = i.getStringExtra("recipient").split("-", 2)[1]; } else { recipient = i.getStringExtra("recipient"); } sendSMS(); } else if (type.equals("email")) { recipient = i.getStringExtra("recipient"); username = Encryption.decryptString(i.getStringExtra("username"), Encryption.KEY); pass = Encryption.decryptString(i.getStringExtra("pass"), Encryption.KEY); subject = i.getStringExtra("subject"); sendEmail(); } else if (type.equals("facebook")) { postFacebook(); } }
/** @param password the password to set */ public void setPassword(String password) throws NoSuchElementException, MailExceptionWrapper { this.session = null; try { Encryption encryption = new Encryption(); this.password = encryption.check_decrypt(password); } catch (GeneralSecurityException ex) { throw new MailExceptionWrapper(ex); } }
public static void main(String args[]) { Scanner scan = new Scanner(System.in); System.out.println("Enter a secret message: "); String secret = scan.nextLine(); System.out.println("To encrypt: " + secret); Encryption enc = new Encryption(); String encStr = enc.encrypt(secret); // Encrypt the original String System.out.println("Encrypted: " + encStr); String decStr = enc.decrypt(encStr); System.out.println("Decrypted: " + decStr); // Decrypt the encrypted string }
public String getString(String key) { String value = getClearString(key); if (value != null && encryption.isEncrypted(value)) { try { value = encryption.decrypt(value); } catch (Exception e) { throw new IllegalStateException( "Fail to decrypt the property " + key + ". Please check your secret key.", e); } } return value; }
/** Marshall the given parameter object, and output to a SdkJsonGenerator */ public void marshall(Encryption encryption, StructuredJsonGenerator jsonGenerator) { if (encryption == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } try { jsonGenerator.writeStartObject(); if (encryption.getMode() != null) { jsonGenerator.writeFieldName("Mode").writeValue(encryption.getMode()); } if (encryption.getKey() != null) { jsonGenerator.writeFieldName("Key").writeValue(encryption.getKey()); } if (encryption.getKeyMd5() != null) { jsonGenerator.writeFieldName("KeyMd5").writeValue(encryption.getKeyMd5()); } if (encryption.getInitializationVector() != null) { jsonGenerator .writeFieldName("InitializationVector") .writeValue(encryption.getInitializationVector()); } jsonGenerator.writeEndObject(); } catch (Throwable t) { throw new SdkClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } }
boolean equalsPass(String string) { try { if (Encryption.md5(string).equals(getEncMasterPassword())) return true; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return false; }
public static void main(String[] args) { Encryption enc = new Encryption("hello"); String key = null; String encvalue = null; if (enc.isEncryptable()) { key = enc.getEncryptionKey(); encvalue = enc.getEncrypted(); } System.out.println("key = " + key); System.out.println("encValue = " + encvalue); Decryption dec = new Decryption(key, encvalue); if (dec.isDecryptable()) { System.out.println(dec.getDecrypted()); } }
public Encryption unmarshall(JsonUnmarshallerContext context) throws Exception { Encryption encryption = new Encryption(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) return null; while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("Mode", targetDepth)) { context.nextToken(); encryption.setMode(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("Key", targetDepth)) { context.nextToken(); encryption.setKey(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("KeyMd5", targetDepth)) { context.nextToken(); encryption.setKeyMd5(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("InitializationVector", targetDepth)) { context.nextToken(); encryption.setInitializationVector( context.getUnmarshaller(String.class).unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return encryption; }
public int updateEntry( int id, String key, String value, String uris, String files, double[] location) { int retval; if (mDatabase == null) { retval = -1; } else { ContentValues values = new ContentValues(); try { values.put(Database.C_KEY, Encryption.encrypt(mPassword, key)); values.put(Database.C_VALUE, Encryption.encrypt(mPassword, value)); values.put(Database.C_IMG_URI, Encryption.encrypt(mPassword, uris)); values.put(Database.C_FILES, Encryption.encrypt(mPassword, files)); values.put(Database.C_LAT, Encryption.encrypt(mPassword, Double.toString(location[0]))); values.put(Database.C_LONG, Encryption.encrypt(mPassword, Double.toString(location[1]))); values.put(Database.C_DATE, String.valueOf(System.currentTimeMillis())); } catch (Exception e) { return -1; } retval = mDatabase.update(Database.TABLE_NAME, id, values); } return retval; }