FileDocCategorySizeDatePackage
ExampleUtils.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)1942Wed Oct 01 10:55:30 BST 2008org.bouncycastle.mail.smime.examples

ExampleUtils

public class ExampleUtils extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voiddumpContent(javax.mail.internet.MimeBodyPart bodyPart, java.lang.String fileName)
Dump the content of the passed in BodyPart to the file fileName.

throws
MessagingException
throws
IOException

        //
        // print mime type of compressed content
        //
        System.out.println("content type: " + bodyPart.getContentType());
        
        //
        // recover the compressed content
        //
        OutputStream out = new FileOutputStream(fileName);
        InputStream in = bodyPart.getInputStream();
        
        byte[] buf = new byte[10000];
        int    len;
        
        while ((len = in.read(buf, 0, buf.length)) > 0)
        {
            out.write(buf, 0, len);
        }
        
        out.close();
    
public static java.lang.StringfindKeyAlias(java.security.KeyStore store, java.lang.String storeName, char[] password)

        store.load(new FileInputStream(storeName), password);
    
        Enumeration e = store.aliases();
        String      keyAlias = null;
    
        while (e.hasMoreElements())
        {
            String  alias = (String)e.nextElement();
    
            if (store.isKeyEntry(alias))
            {
                keyAlias = alias;
            }
        }
    
        if (keyAlias == null)
        {
            throw new IllegalArgumentException("can't find a private key in keyStore: " + storeName);
        }
        
        return keyAlias;