private static byte[] retrieve(Context context, String key) throws IOException { SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0); String encodedValue = settings.getString(key, ""); if (TextUtils.isEmpty(encodedValue)) return null; else return Base64.decode(encodedValue); }
private byte[] decodeAndDecryptBytes(String body) throws InvalidMessageException { try { byte[] decodedBody = Base64.decode(body); return decryptBytes(decodedBody); } catch (IOException e) { throw new InvalidMessageException("Bad Base64 Encoding...", e); } }
public OutgoingGroupMediaMessage( @NonNull Recipients recipients, @NonNull String encodedGroupContext, @NonNull List<Attachment> avatar, long sentTimeMillis) throws IOException { super( recipients, encodedGroupContext, avatar, sentTimeMillis, ThreadDatabase.DistributionTypes.CONVERSATION); this.group = GroupContext.parseFrom(Base64.decode(encodedGroupContext)); }
private void deliver(MasterSecret masterSecret, SendReq message) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions { TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret); byte[] groupId = GroupUtil.getDecodedId(message.getTo()[0].getString()); Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false); List<PushAddress> addresses = getPushAddresses(recipients); List<TextSecureAttachment> attachments = getAttachments(masterSecret, message); if (MmsSmsColumns.Types.isGroupUpdate(message.getDatabaseMessageBox()) || MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox())) { String content = PartParser.getMessageText(message.getBody()); if (content != null && !content.trim().isEmpty()) { PushMessageProtos.PushMessageContent.GroupContext groupContext = PushMessageProtos.PushMessageContent.GroupContext.parseFrom(Base64.decode(content)); TextSecureAttachment avatar = attachments.isEmpty() ? null : attachments.get(0); TextSecureGroup.Type type = MmsSmsColumns.Types.isGroupQuit(message.getDatabaseMessageBox()) ? TextSecureGroup.Type.QUIT : TextSecureGroup.Type.UPDATE; TextSecureGroup group = new TextSecureGroup( type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar); TextSecureMessage groupMessage = new TextSecureMessage(message.getSentTimestamp(), group, null, null); messageSender.sendMessage(addresses, groupMessage); } } else { String body = PartParser.getMessageText(message.getBody()); TextSecureGroup group = new TextSecureGroup(groupId); TextSecureMessage groupMessage = new TextSecureMessage(message.getSentTimestamp(), group, attachments, body); messageSender.sendMessage(addresses, groupMessage); } }