IAIK PKCS#11 Wrapper
version 1.5

iaik.pkcs.pkcs11
Class Util

java.lang.Object
  |
  +--iaik.pkcs.pkcs11.Util

public class Util
extends java.lang.Object

A class consisting of static methods only which provide certain static piecec of code that are used frequently in this project.

Version:
1.0
Author:
Karl Scheibelhofer

Constructor Summary
Util()
           
 
Method Summary
static CK_ATTRIBUTE[] convertAttributesVectorToArray(java.util.Vector attributes)
          Converts the given vector into an array of CK_ATTRIBUTE elements.
static CK_DATE convertToCkDate(java.util.Date date)
          Convert the given Date object to a CK_DATE object.
static java.util.Date convertToDate(CK_DATE ckDate)
          Convert the given CK_DATE object to a Date object.
static java.util.Date parseTime(char[] timeChars)
          Parse a time character array as defined in PKCS#11 and return is as a Date object.
static char[] toCharArray(int number, int exactArrayLength)
          Converts the given number into a char-array.
static char[] toPaddedCharArray(java.lang.String string, int exactArrayLength, char paddingChar)
          Converts the given string to a char-array of exactly the given length.
static byte[] unsignedBigIntergerToByteArray(java.math.BigInteger bigInteger)
          Convert a BigInteger to a byte-array, but treat the byte-array given from the BigInteger as unsigned and removing any leading zero bytes; e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

parseTime

public static java.util.Date parseTime(char[] timeChars)
Parse a time character array as defined in PKCS#11 and return is as a Date object.
Parameters:
timeChars - A time encoded as character array as specified in PKCS#11.
Returns:
A Date object set to the time indicated in the given char-array. null, if the given char array is null or the format is wrong.

convertToDate

public static java.util.Date convertToDate(CK_DATE ckDate)
Convert the given CK_DATE object to a Date object.
Parameters:
ckDate - The object providing the date information.
Returns:
The new Date object or null, if the given ckDate is null.

convertToCkDate

public static CK_DATE convertToCkDate(java.util.Date date)
Convert the given Date object to a CK_DATE object.
Parameters:
date - The object providing the date information.
Returns:
The new CK_DATE object or null, if the given date is null.

toCharArray

public static char[] toCharArray(int number,
                                 int exactArrayLength)
Converts the given number into a char-array. If the length of the array is shorter than the required exact length, the array is padded with leading '0' chars. If the array is longer than the wanted length the most significant digits are cut off until the array has the exact length.
Parameters:
number - The number to convert to a char array.
exactArrayLength - The exact length of the returned array.
Returns:
The numebr as char array, one char for each decimal digit.

toPaddedCharArray

public static char[] toPaddedCharArray(java.lang.String string,
                                       int exactArrayLength,
                                       char paddingChar)
Converts the given string to a char-array of exactly the given length. If the given string is short than the wanted length, then the array is padded with trailing padding chars. If the string is longer, the last character are cut off that the string has the wanted size.
Parameters:
string - The string to convert.
exactArrayLength - The length of the retirned char-array.
paddingChar - The character to use for padding, if necessary.
Returns:
The string as char array, padded or cut off, if necessary. The array will have length exactArrayLength. null, if the given string is null.

unsignedBigIntergerToByteArray

public static byte[] unsignedBigIntergerToByteArray(java.math.BigInteger bigInteger)
Convert a BigInteger to a byte-array, but treat the byte-array given from the BigInteger as unsigned and removing any leading zero bytes; e.g. a 1024 bit integer with its highest bit set will result in an 128 byte array.
Parameters:
bigInteger - The BigInteger to convert.
Returns:
The byte-array representation of the BigInterger without signum-bit. null, if the BigInteger is null.

convertAttributesVectorToArray

public static CK_ATTRIBUTE[] convertAttributesVectorToArray(java.util.Vector attributes)
Converts the given vector into an array of CK_ATTRIBUTE elements. Elements not of type CK_ATTRIBUTE will not be present in the resulting array and be set to null.
Parameters:
attributes - The vector which contains the attributes.
Returns:
The array of the attributes.

IAIK PKCS#11 Wrapper
version 1.5

IAIK JavaSecurity Website http://jce.iaik.tugraz.at/

IAIK at Graz University of Technology, Austria, Europe
Copyright 2001-2004, IAIK, Graz University of Technology, Inffeldgasse 16a, 8010 Graz, Austria. All Rights Reserved.
version 1.5