KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > crypto > KeyAttachment


1 package net.suberic.pooka.crypto;
2
3 import net.suberic.pooka.*;
4 import net.suberic.crypto.*;
5
6 import javax.mail.internet.*;
7 import javax.mail.*;
8 import javax.activation.DataHandler JavaDoc;
9
10 import java.security.Key JavaDoc;
11
12 import java.io.*;
13
14 /**
15  * A signed attachment.
16  */

17 public class KeyAttachment extends Attachment {
18
19   boolean parsed = false;
20
21   /**
22    * Creates a KeyAttachment out of a MimePart.
23    */

24   public KeyAttachment(MimePart mp) throws MessagingException {
25     super(mp);
26   }
27
28   /**
29    * Returns the attached keys.
30    */

31   public Key JavaDoc[] extractKeys(EncryptionUtils utils) throws MessagingException, java.io.IOException JavaDoc, java.security.GeneralSecurityException JavaDoc {
32     net.suberic.crypto.UpdatableMBP mbp = new net.suberic.crypto.UpdatableMBP();
33
34     mbp.setContent(getDataHandler().getContent(), getMimeType().toString());
35     mbp.updateMyHeaders();
36     
37     if (utils == null) {
38       utils = net.suberic.crypto.EncryptionManager.getEncryptionUtils(mbp);
39     }
40
41     if (utils != null)
42       return utils.extractKeys(mbp);
43     else
44       return null;
45   }
46
47 }
48
Popular Tags