com.cryptware.jdigitsign
Class DigitalSignature

java.lang.Object
  extended by com.cryptware.jdigitsign.DigitalSignature

public class DigitalSignature
extends java.lang.Object

Main class for qualified digital signature with CAdES and/or PKCS#7 format

Author:
Ugo Chirico

Field Summary
static int ASK_FOR_SLOT
           
static long ERROR_CANCELLED
           
static long ERROR_CERTIFICATE_NOT_FOUND
           
static long ERROR_INVALID_CMS
           
static long ERROR_INVALID_SLOT_INDEX
           
static long ERROR_NO_MATCHING_ATR_FOUND
           
static long ERROR_NO_SLOTS_FOUND
           
static long ERROR_NO_TOKEN_INSERTED
           
static long ERROR_PRIVATE_KEY_NOT_FOUND
           
static long ERROR_TSP_EXCEPTION
           
static java.lang.String VERSION
          The library Version
 
Constructor Summary
DigitalSignature(java.lang.String cryptokiPath)
          Initializes a new instance of the DigitalSignature class.
 
Method Summary
 void closeSession()
          Closes the session.
static java.lang.String getMathingCryptokiPath()
          Searchs for a matching cryptoki based upon the ATR of the smart card and returns the cryptoki path to be used in DigitalSignature Constructor
 void login(java.lang.String pin)
          Logins the with specified pin.
 void logout()
          Logouts this instance.
 void openSession(int slotIndex)
          Opens the session.
 byte[] sign(byte[] data, CertificateSelector selector)
          Signs the specified data and add a time stamp taken from the given TSA Client
 byte[] sign(byte[] data, CertificateSelector selector, boolean cades)
          Signs the specified data and add a time stamp taken from the given TSA Client
 byte[] sign(byte[] data, CertificateSelector selector, boolean cades, TSAClient tsaClient)
          Signs the specified data and add a time stamp taken from the given TSA Client
 boolean verify(byte[] data)
          Verifies the specified signature.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASK_FOR_SLOT

public static final int ASK_FOR_SLOT
See Also:
Constant Field Values

ERROR_NO_SLOTS_FOUND

public static final long ERROR_NO_SLOTS_FOUND
See Also:
Constant Field Values

ERROR_INVALID_SLOT_INDEX

public static final long ERROR_INVALID_SLOT_INDEX
See Also:
Constant Field Values

ERROR_NO_TOKEN_INSERTED

public static final long ERROR_NO_TOKEN_INSERTED
See Also:
Constant Field Values

ERROR_CANCELLED

public static final long ERROR_CANCELLED
See Also:
Constant Field Values

ERROR_CERTIFICATE_NOT_FOUND

public static final long ERROR_CERTIFICATE_NOT_FOUND
See Also:
Constant Field Values

ERROR_PRIVATE_KEY_NOT_FOUND

public static final long ERROR_PRIVATE_KEY_NOT_FOUND
See Also:
Constant Field Values

ERROR_INVALID_CMS

public static final long ERROR_INVALID_CMS
See Also:
Constant Field Values

ERROR_TSP_EXCEPTION

public static final long ERROR_TSP_EXCEPTION
See Also:
Constant Field Values

ERROR_NO_MATCHING_ATR_FOUND

public static final long ERROR_NO_MATCHING_ATR_FOUND
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
The library Version

See Also:
Constant Field Values
Constructor Detail

DigitalSignature

public DigitalSignature(java.lang.String cryptokiPath)
                 throws java.io.IOException,
                        iaik.pkcs.pkcs11.wrapper.PKCS11Exception
Initializes a new instance of the DigitalSignature class.

Parameters:
cryptokiPath - The PKCS11 path.
Throws:
java.io.IOException
iaik.pkcs.pkcs11.wrapper.PKCS11Exception
Method Detail

getMathingCryptokiPath

public static java.lang.String getMathingCryptokiPath()
                                               throws DigitalSignatureException
Searchs for a matching cryptoki based upon the ATR of the smart card and returns the cryptoki path to be used in DigitalSignature Constructor

Returns:
the cryptoki path for the inserted smart card if any
Throws:
DigitalSignatureException - with error ERROR_NO_MATCHING_ATR_FOUND if no matching ATR is found

openSession

public void openSession(int slotIndex)
                 throws DigitalSignatureException
Opens the session.

Parameters:
slotIndex - index of the slot to opem
Throws:
DigitalSignatureException

closeSession

public void closeSession()
                  throws DigitalSignatureException
Closes the session.

Throws:
DigitalSignatureException

login

public void login(java.lang.String pin)
           throws DigitalSignatureException
Logins the with specified pin.

Parameters:
pin -
Throws:
DigitalSignatureException

logout

public void logout()
            throws DigitalSignatureException
Logouts this instance.

Throws:
DigitalSignatureException

sign

public byte[] sign(byte[] data,
                   CertificateSelector selector)
            throws DigitalSignatureException
Signs the specified data and add a time stamp taken from the given TSA Client

Parameters:
data - the data
selector - the certificate selector
Returns:
signature in PKCS# format DER encoded
Throws:
DigitalSignatureException

sign

public byte[] sign(byte[] data,
                   CertificateSelector selector,
                   boolean cades)
            throws DigitalSignatureException
Signs the specified data and add a time stamp taken from the given TSA Client

Parameters:
data - the data
selector - the certificate selector
cades - specifies if CAdES signature is needed
Returns:
signature in PKCS#7 or CAdES format DER encoded
Throws:
DigitalSignatureException

sign

public byte[] sign(byte[] data,
                   CertificateSelector selector,
                   boolean cades,
                   TSAClient tsaClient)
            throws DigitalSignatureException,
                   java.io.IOException
Signs the specified data and add a time stamp taken from the given TSA Client

Parameters:
data - the data
selector - the certificate selector
cades - specifies if CAdES signature is needed
tsaClient - the TSA client
Returns:
signature in PKCS#7 or CAdES format DER encoded
Throws:
DigitalSignatureException
TSPException
java.io.IOException

verify

public boolean verify(byte[] data)
               throws DigitalSignatureException
Verifies the specified signature.

Parameters:
data - the data to verify
Returns:
true if the verification succeeds false otherwise
Throws:
CMSException
DigitalSignatureException