edu.vt.middleware.crypt.util
Class CryptWriter

java.lang.Object
  extended by edu.vt.middleware.crypt.util.CryptWriter

public final class CryptWriter
extends Object

Helper class for performing I/O write operations on cryptographic data.

Version:
$Revision: 2745 $
Author:
Middleware Services

Constructor Summary
protected CryptWriter()
          Protected constructor of utility class.
 
Method Summary
static void writeEncodedCertificate(Certificate cert, File file)
          Writes the supplied certificate to the file using its native encoding.
static void writeEncodedCertificate(Certificate cert, OutputStream out)
          Writes the supplied certificate to the output stream using its native encoding.
static void writeEncodedCertificates(Certificate[] certs, File file)
          Writes the supplied certificates in sequence to the file using their native encoding.
static void writeEncodedCertificates(Certificate[] certs, OutputStream out)
          Writes the supplied certificates in sequence to the output stream using their native encoding.
static void writeEncodedKey(Key key, File file)
          Writes the supplied key to the file using its native encoding.
static void writeEncodedKey(Key key, OutputStream out)
          Writes the supplied key to the output stream using its native encoding.
static void writePemCertificate(Certificate cert, File file)
          Writes the supplied certificate to the supplied file in PEM format.
static void writePemCertificate(Certificate cert, OutputStream out)
          Writes the supplied certificate to the supplied output stream in PEM format.
static void writePemCertificates(Certificate[] certs, File file)
          Writes the concatenation of the given certificates in PEM format to the given file.
static void writePemCertificates(Certificate[] certs, OutputStream out)
          Writes the concatenation of the given certificates in PEM format to the given output stream.
static void writePemKey(PrivateKey key, char[] password, SecureRandom random, File file)
          Writes the supplied private key to the supplied file in encrypted PEM format.
static void writePemKey(PrivateKey key, char[] password, SecureRandom random, OutputStream out)
          Writes the supplied private key to the supplied output stream in PEM format.
static void writePemKey(PublicKey key, File file)
          Writes the supplied public key to the supplied file in PEM format.
static void writePemKey(PublicKey key, OutputStream out)
          Writes the supplied public key to the supplied output stream in PEM format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptWriter

protected CryptWriter()
Protected constructor of utility class.

Method Detail

writeEncodedKey

public static void writeEncodedKey(Key key,
                                   File file)
                            throws IOException
Writes the supplied key to the file using its native encoding. The format and encoding of the key is commonly determined by the key type. See writeEncodedKey(Key, OutputStream) for more information.

Parameters:
key - Key to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.

writeEncodedKey

public static void writeEncodedKey(Key key,
                                   OutputStream out)
                            throws IOException
Writes the supplied key to the output stream using its native encoding. The format and encoding of the key is commonly determined by the key type:

Parameters:
key - Key to write.
out - Ouput stream to write key data to.
Throws:
IOException - On write errors.

writePemKey

public static void writePemKey(PublicKey key,
                               File file)
                        throws IOException
Writes the supplied public key to the supplied file in PEM format.

Parameters:
key - Public key to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.

writePemKey

public static void writePemKey(PublicKey key,
                               OutputStream out)
                        throws IOException
Writes the supplied public key to the supplied output stream in PEM format.

Parameters:
key - Public key to write to file.
out - Ouput stream to write key data to.
Throws:
IOException - On write errors.

writePemKey

public static void writePemKey(PrivateKey key,
                               char[] password,
                               SecureRandom random,
                               File file)
                        throws IOException
Writes the supplied private key to the supplied file in encrypted PEM format.

Parameters:
key - Private key to write to file.
password - Password used to encrypt private key using 256-bit AES encryption; may be null to indicate no encryption.
random - Secure random provider used for encrypting private key.
file - Output file descriptor.
Throws:
IOException - On write errors.

writePemKey

public static void writePemKey(PrivateKey key,
                               char[] password,
                               SecureRandom random,
                               OutputStream out)
                        throws IOException
Writes the supplied private key to the supplied output stream in PEM format.

Parameters:
key - Private key to write to file.
password - Password used to encrypt private key using 256-bit AES encryption; may be null to indicate no encryption.
random - Secure random provider used for encrypting private key.
out - Ouput stream to write key data to.
Throws:
IOException - On write errors.

writeEncodedCertificate

public static void writeEncodedCertificate(Certificate cert,
                                           File file)
                                    throws CryptException,
                                           IOException
Writes the supplied certificate to the file using its native encoding. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

Parameters:
cert - Certificate to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.
CryptException - If the given cert cannot be decoded to bytes.

writeEncodedCertificate

public static void writeEncodedCertificate(Certificate cert,
                                           OutputStream out)
                                    throws CryptException,
                                           IOException
Writes the supplied certificate to the output stream using its native encoding. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

Parameters:
cert - Certificate to write to file.
out - Ouput stream to write cert data to.
Throws:
IOException - On write errors.
CryptException - If the given cert cannot be decoded to bytes.

writePemCertificate

public static void writePemCertificate(Certificate cert,
                                       File file)
                                throws IOException
Writes the supplied certificate to the supplied file in PEM format.

Parameters:
cert - Certificate to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.

writePemCertificate

public static void writePemCertificate(Certificate cert,
                                       OutputStream out)
                                throws IOException
Writes the supplied certificate to the supplied output stream in PEM format.

Parameters:
cert - Certificate to write to the output stream.
out - Ouput stream to write cert data to.
Throws:
IOException - On write errors.

writeEncodedCertificates

public static void writeEncodedCertificates(Certificate[] certs,
                                            File file)
                                     throws CryptException,
                                            IOException
Writes the supplied certificates in sequence to the file using their native encoding. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

Parameters:
certs - Certificates to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.
CryptException - If the given cert cannot be decoded to bytes.

writeEncodedCertificates

public static void writeEncodedCertificates(Certificate[] certs,
                                            OutputStream out)
                                     throws CryptException,
                                            IOException
Writes the supplied certificates in sequence to the output stream using their native encoding. It is assumed that each certificate type would have only a single form of encoding; for example, X.509 certificates would be encoded as ASN.1 DER.

Parameters:
certs - Certificates to write to the output stream.
out - Ouput stream to write cert data to.
Throws:
IOException - On write errors.
CryptException - If the given cert cannot be decoded to bytes.

writePemCertificates

public static void writePemCertificates(Certificate[] certs,
                                        File file)
                                 throws IOException
Writes the concatenation of the given certificates in PEM format to the given file.

Parameters:
certs - Certificates to write to file.
file - Output file descriptor.
Throws:
IOException - On write errors.

writePemCertificates

public static void writePemCertificates(Certificate[] certs,
                                        OutputStream out)
                                 throws IOException
Writes the concatenation of the given certificates in PEM format to the given output stream.

Parameters:
certs - Certificates to write to the output stream.
out - Ouput stream to write cert data to.
Throws:
IOException - On write errors.


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.