public class Utils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
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 iaik.asn1.structures.AlgorithmID |
createOaepAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID)
Creates an RSA-OAEP AlgorithmID for the given hash algorithm.
|
static iaik.asn1.structures.AlgorithmID |
createOaepAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID,
iaik.asn1.structures.AlgorithmID pSourceID,
byte[] label)
Creates an RSA-OAEP AlgorithmID with the supplied parameters (hash algorithm id,
PSource algorithm and label).
|
static iaik.asn1.structures.AlgorithmID |
createPssAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID)
Creates an RSA-PSS AlgorithmID for the given hash algorithm.
|
static iaik.asn1.structures.AlgorithmID |
createPssAlgorithmID(iaik.asn1.structures.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(iaik.asn1.structures.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,
iaik.asn1.structures.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,
iaik.asn1.structures.PolicyInformation[] policies,
boolean includeIssuerSerial,
SecurityProvider securityProvider)
Creates an ESS SigningCertificate for the given X.509 certificates
and policy informations.
|
static SigningCertificate |
makeSigningCertificate(ESSCertID[] certIDs,
iaik.asn1.structures.PolicyInformation[] policies)
Creates an ESS SigningCertificate for the given certIDs
and policy informations.
|
static SigningCertificateV2 |
makeSigningCertificateV2(java.security.cert.Certificate[] certs,
iaik.asn1.structures.AlgorithmID hashAlgorithm,
iaik.asn1.structures.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,
iaik.asn1.structures.AlgorithmID hashAlgorithm,
iaik.asn1.structures.PolicyInformation[] policies,
boolean includeIssuerSerial,
SecurityProvider securityProvider)
Creates an ESS SigningCertificateV2 for the given X.509 certificates
and policy informations.
|
static SigningCertificateV2 |
makeSigningCertificateV2(ESSCertIDv2[] certIDs,
iaik.asn1.structures.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.
|
public static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs, iaik.asn1.structures.PolicyInformation[] policies, boolean includeIssuerSerial) throws CMSException
certs
- the certificates to be identifiedpolicies
- the PolicyInformation terms to be includedincludeIssuerSerial
- whether to set the issuerSerial field for
for the ESSCertIDs to be createdCMSException
public static SigningCertificate makeSigningCertificate(java.security.cert.Certificate[] certs, iaik.asn1.structures.PolicyInformation[] policies, boolean includeIssuerSerial, SecurityProvider securityProvider) throws CMSException
certs
- the certificates to be identifiedpolicies
- the PolicyInformation terms to be includedincludeIssuerSerial
- whether to set the issuerSerial field for
for the ESSCertIDs to be createdsecurityProvider
- 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.CMSException
public static SigningCertificate makeSigningCertificate(ESSCertID[] certIDs, iaik.asn1.structures.PolicyInformation[] policies)
certIDs
- the ESSCertIDs to be includedpolicies
- the PolicyInformation terms to be includedpublic static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs, iaik.asn1.structures.AlgorithmID hashAlgorithm, iaik.asn1.structures.PolicyInformation[] policies, boolean includeIssuerSerial) throws CMSException
certs
- the certificates to be identifiedhashAlgorithm
- the hash algorithm to be used for cert hash
calculation (default: SHA-256)policies
- the PolicyInformation terms to be includedincludeIssuerSerial
- whether to set the issuerSerial field for
for the ESSCertIDv2 objects to be createdCMSException
public static SigningCertificateV2 makeSigningCertificateV2(java.security.cert.Certificate[] certs, iaik.asn1.structures.AlgorithmID hashAlgorithm, iaik.asn1.structures.PolicyInformation[] policies, boolean includeIssuerSerial, SecurityProvider securityProvider) throws CMSException
certs
- the certificates to be identifiedhashAlgorithm
- the hash algorithm to be used for cert hash
calculation (default: SHA-256)policies
- the PolicyInformation terms to be includedincludeIssuerSerial
- whether to set the issuerSerial field for
for the ESSCertIDv2 objects to be createdsecurityProvider
- 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.CMSException
public static SigningCertificateV2 makeSigningCertificateV2(ESSCertIDv2[] certIDs, iaik.asn1.structures.PolicyInformation[] policies)
certIDs
- the ESSCertIDv2 objects to be includedpolicies
- the PolicyInformation terms to be includedpublic static void copyStream(java.io.InputStream source, java.io.OutputStream destination, byte[] buffer) throws java.io.IOException
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.java.io.IOException
- If reading from the source or writing to the
destination fails.public static long copy(java.io.InputStream source, java.io.OutputStream destination, byte[] buffer) throws java.io.IOException
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.java.io.IOException
- If reading from the source or writing to the
destination fails.public static java.lang.String printIndented(java.lang.String msg, boolean indentFirst)
msg
- the (multi line) message to be printedpublic static java.lang.String printIndented(java.lang.String msg, boolean indentFirst, java.lang.String indentToken)
msg
- the (multi line) message to be printedindentFirst
- whether to indent the first line or leave it unindentedindentToken
- the token which shall be printed in front of each linepublic static void printIndented(java.lang.String msg, boolean indentFirst, java.lang.StringBuffer buf)
msg
- the (multi line) message to be printedindentFirst
- whether to indent the first line or leave it unindentedbuf
- the StringBuffer to which to print the messagepublic static void printIndented(java.lang.String msg, boolean indentFirst, java.lang.String indentToken, java.lang.StringBuffer buf)
msg
- the (multi line) message to be printedindentFirst
- whether to indent the first line or leave it unindentedindentToken
- the token which shall be printed in front of each linebuf
- the StringBuffer to which to print the messagepublic static boolean isClassAvailable(java.lang.String className)
className
- the name of the class to be checked for availabilitytrue
if the class with the given name is available;
false
if it is not availablepublic static int getShakeOutputLen(iaik.asn1.structures.AlgorithmID shakeID)
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 }
shakeID
- the SHAKE-LEN algorithm id-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 idpublic static double getIaikProviderVersion()
public static iaik.asn1.structures.AlgorithmID createPssAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID) throws java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
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.
hashAlgID
- the hash algorithm to be usedjava.security.InvalidAlgorithmParameterException
- if the PSS parameters cannot be created/setjava.security.NoSuchAlgorithmException
- if there is no AlgorithmParameters implementation
for RSA-PSS, or the given hash algorithm or the MGF1 mask
generation function is not supportedpublic static iaik.asn1.structures.AlgorithmID createPssAlgorithmID(iaik.asn1.structures.AlgorithmID hashID, int saltLength) throws java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
hashID
- the hash algorithm to be usedsaltLength
- the salt length to be usedjava.security.InvalidAlgorithmParameterException
- if the parameters cannot be created/setjava.security.NoSuchAlgorithmException
- if there is no AlgorithmParameters implementation
for RSA-PSS, or the given hash algorithm or the MGF1 mask
generation function is not supportedpublic static iaik.asn1.structures.AlgorithmID createOaepAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID) throws java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
MGF1 is used as mask generation function mask generation function, pSpecified as PSource algorithm and an empty string as label.
hashAlgID
- the hash algorithm to be usedjava.security.InvalidAlgorithmParameterException
- if the parameters cannot be created/setjava.security.NoSuchAlgorithmException
- if there is no AlgorithmParameters implementation
for RSA-OAEP, or the given hash algorithm or the MGF1 mask
generation function is not supportedpublic static iaik.asn1.structures.AlgorithmID createOaepAlgorithmID(iaik.asn1.structures.AlgorithmID hashAlgID, iaik.asn1.structures.AlgorithmID pSourceID, byte[] label) throws java.security.InvalidAlgorithmParameterException, java.security.NoSuchAlgorithmException
hashAlgID
- the hash algorithm to be usedpSourceID
- the PSource algorithmlabel
- the value of the PSource label parameterjava.security.InvalidAlgorithmParameterException
- if the parameters cannot be created/setjava.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