iaik.cms
Class Utils

java.lang.Object
  extended by iaik.cms.Utils

public class Utils
extends java.lang.Object

Some basic utility methods.


Method Summary
static long copy(java.io.InputStream source, java.io.OutputStream destination, byte[] buffer)
          Reads all data (until EOF is reached) from the given source to the destination stream.
static void copyStream(java.io.InputStream source, java.io.OutputStream destination, byte[] buffer)
          Reads all data (until EOF is reached) from the given source to the destination stream.
static double getIaikProviderVersion()
          Gets the version number of the IAIK-JCE provider used for this demos.
static boolean isClassAvailable(java.lang.String className)
          Check if the class with the specified name is available
static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs, PolicyInformation[] policies, boolean includeIssuerSerial)
          Creates an ESS SigningCertificate for the given X.509 certificates and policy informations.
static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs, PolicyInformation[] policies, boolean includeIssuerSerial, SecurityProvider securityProvider)
          Creates an ESS SigningCertificate for the given X.509 certificates and policy informations.
static SigningCertificate makeSigningCertificate(ESSCertID[] certIDs, PolicyInformation[] policies)
          Creates an ESS SigningCertificate for the given certIDs and policy informations.
static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs, AlgorithmID hashAlgorithm, PolicyInformation[] policies, boolean includeIssuerSerial)
          Creates an ESS SigningCertificateV2 for the given X.509 certificates and policy informations.
static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs, AlgorithmID hashAlgorithm, PolicyInformation[] policies, boolean includeIssuerSerial, SecurityProvider securityProvider)
          Creates an ESS SigningCertificateV2 for the given X.509 certificates and policy informations.
static SigningCertificateV2 makeSigningCertificateV2(ESSCertIDv2[] certIDs, PolicyInformation[] policies)
          Creates an ESS SigningCertificateV2 for the given certIDs and policy informations.
static java.lang.String printIndented(java.lang.String msg, boolean indentFirst)
          Creates a new String from the given (multi line) message where each line is indented with a space " " token.
static java.lang.String printIndented(java.lang.String msg, boolean indentFirst, java.lang.String indentToken)
          Creates a new String from the given (multi line) message where each line is indented with the given indent token.
static void printIndented(java.lang.String msg, boolean indentFirst, java.lang.StringBuffer buf)
          Prints the given (multi line) message indented to the supplied StringBuffer.
static void printIndented(java.lang.String msg, boolean indentFirst, java.lang.String indentToken, java.lang.StringBuffer buf)
          Prints the given (multi line) message indented to the supplied StringBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeSigningCertificate

public static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs,
                                                        PolicyInformation[] policies,
                                                        boolean includeIssuerSerial)
                                                 throws CMSException
Creates an ESS SigningCertificate for the given X.509 certificates and policy informations.

Parameters:
certs - the certificates to be identified
policies - the PolicyInformation terms to be included
includeIssuerSerial - whether to set the issuerSerial field for for the ESSCertIDs to be created
Returns:
the ESS SigningCertificate
Throws:
CMSException

makeSigningCertificate

public static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs,
                                                        PolicyInformation[] policies,
                                                        boolean includeIssuerSerial,
                                                        SecurityProvider securityProvider)
                                                 throws CMSException
Creates an ESS SigningCertificate for the given X.509 certificates and policy informations.

Parameters:
certs - the certificates to be identified
policies - the PolicyInformation terms to be included
includeIssuerSerial - whether to set the issuerSerial field for for the ESSCertIDs to be created
securityProvider - the SecurityProvider to be used to calculate an SHA-1 hash from the encoded certificates required for the ESSCertID objects of the SigningCertificate by using the SecurityProvider method getHash() which may be overriden by an application, if required.
Returns:
the ESS SigningCertificate
Throws:
CMSException

makeSigningCertificate

public static SigningCertificate makeSigningCertificate(ESSCertID[] certIDs,
                                                        PolicyInformation[] policies)
Creates an ESS SigningCertificate for the given certIDs and policy informations.

Parameters:
certIDs - the ESSCertIDs to be included
policies - the PolicyInformation terms to be included
Returns:
the ESS SigningCertificate

makeSigningCertificateV2

public static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs,
                                                            AlgorithmID hashAlgorithm,
                                                            PolicyInformation[] policies,
                                                            boolean includeIssuerSerial)
                                                     throws CMSException
Creates an ESS SigningCertificateV2 for the given X.509 certificates and policy informations.

Parameters:
certs - the certificates to be identified
hashAlgorithm - the hash algorithm to be used for cert hash calculation (default: SHA-256)
policies - the PolicyInformation terms to be included
includeIssuerSerial - whether to set the issuerSerial field for for the ESSCertIDv2 objects to be created
Returns:
the ESS SigningCertificateV2
Throws:
CMSException

makeSigningCertificateV2

public static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs,
                                                            AlgorithmID hashAlgorithm,
                                                            PolicyInformation[] policies,
                                                            boolean includeIssuerSerial,
                                                            SecurityProvider securityProvider)
                                                     throws CMSException
Creates an ESS SigningCertificateV2 for the given X.509 certificates and policy informations.

Parameters:
certs - the certificates to be identified
hashAlgorithm - the hash algorithm to be used for cert hash calculation (default: SHA-256)
policies - the PolicyInformation terms to be included
includeIssuerSerial - whether to set the issuerSerial field for for the ESSCertIDv2 objects to be created
securityProvider - the SecurityProvider to be used to calculate the hash values from the encoded certificates required for the ESSCertIDv2 objects of the SigningCertificateV2 by using the SecurityProvider method getHash() which may be overriden by an application, if required.
Returns:
the ESS SigningCertificateV2
Throws:
CMSException

makeSigningCertificateV2

public static SigningCertificateV2 makeSigningCertificateV2(ESSCertIDv2[] certIDs,
                                                            PolicyInformation[] policies)
Creates an ESS SigningCertificateV2 for the given certIDs and policy informations.

Parameters:
certIDs - the ESSCertIDv2 objects to be included
policies - the PolicyInformation terms to be included
Returns:
the ESS SigningCertificateV2

copyStream

public static void copyStream(java.io.InputStream source,
                              java.io.OutputStream destination,
                              byte[] buffer)
                       throws java.io.IOException
Reads all data (until EOF is reached) from the given source to the destination stream. If the destination stream is null, all data is dropped. It uses the given buffer to read data and forward it. If the buffer is null, this method allocates a buffer.

Parameters:
source - The stream providing the data.
destination - The stream that takes the data. If this is null, all data from source will be read and discarded.
buffer - The buffer to use for forwarding. If it is null, the method allocates a buffer.
Throws:
java.io.IOException - If reading from the source or writing to the destination fails.

copy

public static long copy(java.io.InputStream source,
                        java.io.OutputStream destination,
                        byte[] buffer)
                 throws java.io.IOException
Reads all data (until EOF is reached) from the given source to the destination stream. If the destination stream is null, all data is dropped. It uses the given buffer to read data and forward it. If the buffer is null, this method allocates a buffer.

Parameters:
source - The stream providing the data.
destination - The stream that takes the data. If this is null, all data from source will be read and discarded.
buffer - The buffer to use for forwarding. If it is null, the method allocates a buffer.
Returns:
the number of bytes read
Throws:
java.io.IOException - If reading from the source or writing to the destination fails.

printIndented

public static java.lang.String printIndented(java.lang.String msg,
                                             boolean indentFirst)
Creates a new String from the given (multi line) message where each line is indented with a space " " token.

Parameters:
msg - the (multi line) message to be printed
Returns:
the new String

printIndented

public static java.lang.String printIndented(java.lang.String msg,
                                             boolean indentFirst,
                                             java.lang.String indentToken)
Creates a new String from the given (multi line) message where each line is indented with the given indent token.

Parameters:
msg - the (multi line) message to be printed
indentFirst - whether to indent the first line or leave it unindented
indentToken - the token which shall be printed in front of each line
Returns:
the new String

printIndented

public static void printIndented(java.lang.String msg,
                                 boolean indentFirst,
                                 java.lang.StringBuffer buf)
Prints the given (multi line) message indented to the supplied StringBuffer. If the message consists of serveral lines each line is printed indented with the space " " token.

Parameters:
msg - the (multi line) message to be printed
indentFirst - whether to indent the first line or leave it unindented
buf - the StringBuffer to which to print the message

printIndented

public static void printIndented(java.lang.String msg,
                                 boolean indentFirst,
                                 java.lang.String indentToken,
                                 java.lang.StringBuffer buf)
Prints the given (multi line) message indented to the supplied StringBuffer. If the message consists of serveral lines each line is printed indented with the given indent token.

Parameters:
msg - the (multi line) message to be printed
indentFirst - whether to indent the first line or leave it unindented
indentToken - the token which shall be printed in front of each line
buf - the StringBuffer to which to print the message

isClassAvailable

public static boolean isClassAvailable(java.lang.String className)
Check if the class with the specified name is available

Parameters:
className - the name of the class to be checked for availability
Returns:
true if the class with the given name is available; false if it is not available

getIaikProviderVersion

public static double getIaikProviderVersion()
Gets the version number of the IAIK-JCE provider used for this demos.

Returns:
the version number of the IAIK JCA/JCE provider

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 5.1, (c) 2002 IAIK, (c) 2003 - 2010 SIC