Sign and encrypt

This commit is contained in:
M66B
2018-10-28 14:29:45 +00:00
parent 8c081fbbda
commit 7d21a147b1
3 changed files with 77 additions and 36 deletions

View File

@@ -27,9 +27,11 @@ import android.webkit.MimeTypeMap;
import org.jsoup.Jsoup;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -197,6 +199,27 @@ public class MessageHelper {
imessage.setSentDate(new Date());
if (message.from != null && message.from.length > 0)
for (EntityAttachment attachment : attachments)
if (attachment.available && "signature.asc".equals(attachment.name)) {
InternetAddress from = (InternetAddress) message.from[0];
File file = EntityAttachment.getFile(context, attachment.id);
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null)
if (!line.startsWith("-----") && !line.endsWith("-----"))
sb.append(line);
} finally {
if (br != null)
br.close();
}
imessage.addHeader("Autocrypt", "addr=" + from.getAddress() + "; keydata=" + sb.toString());
}
for (final EntityAttachment attachment : attachments)
if (attachment.available && "encrypted.asc".equals(attachment.name)) {
Multipart multipart = new MimeMultipart("encrypted; protocol=\"application/pgp-encrypted\"");