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 AlgorithmID createOaepAlgorithmID(AlgorithmID hashAlgID)
          Creates an RSA-OAEP AlgorithmID for the given hash algorithm.
static AlgorithmID createOaepAlgorithmID(AlgorithmID hashAlgID, AlgorithmID pSourceID, byte[] label)
          Creates an RSA-OAEP AlgorithmID with the supplied parameters (hash algorithm id, PSource algorithm and label).
static AlgorithmID createPssAlgorithmID(AlgorithmID hashAlgID)
          Creates an RSA-PSS AlgorithmID for the given hash algorithm.
static AlgorithmID createPssAlgorithmID(AlgorithmID hashID, int saltLength)
          Creates an RSA-PSS AlgorithmID with the supplied parameters (hash algorithm id and salt length).
static double getIaikProviderVersion()
          Gets the version number of the IAIK-JCE provider used for this demos.
static int getShakeOutputLen(AlgorithmID shakeID)
          Gets the value of the output length parameter of the given SHAKE-LEN Extendable Output Function (XOF) algorithm identifier id as specified by NIST FIPS PUB 202.
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

getShakeOutputLen

public static int getShakeOutputLen(AlgorithmID shakeID)
Gets the value of the output length parameter of the given SHAKE-LEN Extendable Output Function (XOF) algorithm identifier id as specified by NIST FIPS PUB 202.
See NIST algorithm identifier registration at Computer Security Objects Register:
 id-shake128-len OBJECT IDENTIFIER ::= { hashAlgs 17 }

 id-shake256-len OBJECT IDENTIFIER ::= { hashAlgs 18 }

 ShakeOutputLen ::= INTEGER -- Output length in bits


 Alg-SHAKE128-LEN ALGORITHM ::= { OID id-shake128-len PARMS ShakeOutputLen }

 Alg-SHAKE256-LEN ALGORITHM ::= { OID id-shake256-len PARMS ShakeOutputLen }
 

Parameters:
shakeID - the SHAKE-LEN algorithm id
Returns:
the output length parameter (in bytes) or -1 if it is not set or cannot be determined because the parameter is not an ASN.1 INTEGER or because the given AlgorithmID does not present a id-shake128-len or id-shake256-len algorithm id

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

createPssAlgorithmID

public static AlgorithmID createPssAlgorithmID(AlgorithmID hashAlgID)
                                        throws java.security.InvalidAlgorithmParameterException,
                                               java.security.NoSuchAlgorithmException
Creates an RSA-PSS AlgorithmID for the given hash algorithm.

MGF1 is used as mask generation function and the salt length value is set to the length of the output value of the hash algorithm.

Parameters:
hashAlgID - the hash algorithm to be used
Returns:
the RSA-PSS algorithm id
Throws:
java.security.InvalidAlgorithmParameterException - if the PSS parameters cannot be created/set
java.security.NoSuchAlgorithmException - if there is no AlgorithmParameters implementation for RSA-PSS, or the given hash algorithm or the MGF1 mask generation function is not supported

createPssAlgorithmID

public static AlgorithmID createPssAlgorithmID(AlgorithmID hashID,
                                               int saltLength)
                                        throws java.security.InvalidAlgorithmParameterException,
                                               java.security.NoSuchAlgorithmException
Creates an RSA-PSS AlgorithmID with the supplied parameters (hash algorithm id and salt length). MGF1 is used as mask generation function

Parameters:
hashID - the hash algorithm to be used
saltLength - the salt length to be used
Returns:
the RSA-PSS algorithm id with the given parameters
Throws:
java.security.InvalidAlgorithmParameterException - if the parameters cannot be created/set
java.security.NoSuchAlgorithmException - if there is no AlgorithmParameters implementation for RSA-PSS, or the given hash algorithm or the MGF1 mask generation function is not supported

createOaepAlgorithmID

public static AlgorithmID createOaepAlgorithmID(AlgorithmID hashAlgID)
                                         throws java.security.InvalidAlgorithmParameterException,
                                                java.security.NoSuchAlgorithmException
Creates an RSA-OAEP AlgorithmID for the given hash algorithm.

MGF1 is used as mask generation function mask generation function, pSpecified as PSource algorithm and an empty string as label.

Parameters:
hashAlgID - the hash algorithm to be used
Returns:
the RSA-OAEP algorithm id with the given parameters
Throws:
java.security.InvalidAlgorithmParameterException - if the parameters cannot be created/set
java.security.NoSuchAlgorithmException - if there is no AlgorithmParameters implementation for RSA-OAEP, or the given hash algorithm or the MGF1 mask generation function is not supported

createOaepAlgorithmID

public static AlgorithmID createOaepAlgorithmID(AlgorithmID hashAlgID,
                                                AlgorithmID pSourceID,
                                                byte[] label)
                                         throws java.security.InvalidAlgorithmParameterException,
                                                java.security.NoSuchAlgorithmException
Creates an RSA-OAEP AlgorithmID with the supplied parameters (hash algorithm id, PSource algorithm and label). MGF1 is used as mask generation function.

Parameters:
hashAlgID - the hash algorithm to be used
pSourceID - the PSource algorithm
label - the value of the PSource label parameter
Returns:
the RSA-OAEP algorithm id with the given parameters
Throws:
java.security.InvalidAlgorithmParameterException - if the parameters cannot be created/set
java.security.NoSuchAlgorithmException - if there is no AlgorithmParameters implementation for RSA-OAEP, or the given hash algorithm or the MGF1 mask generation function is not supported

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

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC