public class Session extends Object
TokenInfo tokenInfo = token.getTokenInfo();
// check, if log-in of the user is required at all
if (tokenInfo.isLoginRequired()) {
// check, if the token has own means to authenticate the user; e.g. a PIN-pad on the reader
if (tokenInfo.isProtectedAuthenticationPath()) {
System.out.println("Please enter the user PIN at the PIN-pad of your reader.");
session.login(CKU_USER, null); // the token prompts the PIN by other means; e.g. PIN-pad
} else {
System.out.print("Enter user-PIN and press [return key]: ");
System.out.flush();
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String userPINString = input.readLine();
session.login(CKU_USER, userPINString.toCharArray());
}
}
If the application does not need the session any longer, it should close the
session.
session.closeSession();
| Modifier | Constructor and Description |
|---|---|
protected |
Session(Token token,
long sessionHandle)
Constructor taking the token and the session handle.
|
| Modifier and Type | Method and Description |
|---|---|
void |
closeSession()
Closes this session.
|
long |
copyObject(long sourceObjectHandle,
AttributeVector template)
Copy an existing object.
|
long |
createECPrivateKeyObject(AttributeVector template,
byte[] ecPoint) |
long |
createObject(AttributeVector template)
Create a new object on the token (or in the session).
|
long |
createPrivateKeyObject(AttributeVector template,
PublicKey publicKey) |
int |
decrypt(byte[] in,
byte[] out)
Decrypts the given data with the key and mechanism given to the decryptInit method.
|
int |
decrypt(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Decrypts the given data with the key and mechanism given to the decryptInit method.
|
int |
decryptFinal(byte[] out,
int outOfs,
int outLen)
This method finalizes a decryption operation and returns the final result.
|
void |
decryptInit(Mechanism mechanism,
long keyHandle)
Initializes a new decryption operation.
|
int |
decryptSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
byte[] out) |
int |
decryptSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen) |
int |
decryptUpdate(byte[] in,
byte[] out)
This method can be used to decrypt multiple pieces of data; e.g.
|
int |
decryptUpdate(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
This method can be used to decrypt multiple pieces of data; e.g.
|
long |
deriveKey(Mechanism mechanism,
long baseKeyHandle,
AttributeVector template)
Derives a new key from a specified base key using the given mechanism.
|
void |
destroyObject(long objectHandle)
Destroy a certain object on the token (or in the session).
|
int |
digest(byte[] in,
byte[] out)
Digests the given data with the mechanism given to the digestInit method.
|
int |
digest(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Digests the given data with the mechanism given to the digestInit method.
|
int |
digestFinal(byte[] in,
byte[] out)
Digests the given data with the mechanism given to the digestInit method.
|
int |
digestFinal(byte[] out,
int outOfs,
int outLen)
This method finalizes a digesting operation and returns the final result.
|
int |
digestFinal(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Digests the given data with the mechanism given to the digestInit method.
|
void |
digestInit(Mechanism mechanism)
Initializes a new digesting operation.
|
void |
digestKey(long keyHandle)
This method is similar to digestUpdate and can be combined with it during one digesting
operation.
|
int |
digestSingle(Mechanism mechanism,
byte[] in,
byte[] out) |
int |
digestSingle(Mechanism mechanism,
byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen) |
void |
digestUpdate(byte[] in)
This method can be used to digest multiple pieces of data; e.g.
|
void |
digestUpdate(byte[] in,
int inOfs,
int inLen)
This method can be used to digest multiple pieces of data; e.g.
|
int |
encrypt(byte[] in,
byte[] out)
Encrypts the given data with the key and mechanism given to the encryptInit method.
|
int |
encrypt(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Encrypts the given data with the key and mechanism given to the encryptInit method.
|
int |
encryptFinal(byte[] out,
int outOfs,
int outLen)
This method finalizes an encrypt operation and returns the final result.
|
void |
encryptInit(Mechanism mechanism,
long keyHandle)
Initializes a new encryption operation.
|
int |
encryptSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
byte[] out) |
int |
encryptSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen) |
int |
encryptUpdate(byte[] in,
byte[] out)
This method can be used to encrypt multiple pieces of data; e.g.
|
int |
encryptUpdate(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
This method can be used to encrypt multiple pieces of data; e.g.
|
long[] |
findAllObjectsSingle(AttributeVector template) |
long[] |
findObjects(int maxObjectCount)
Finds objects that match the template object passed to findObjectsInit.
|
void |
findObjectsFinal()
Finalizes a find operation.
|
void |
findObjectsInit(AttributeVector template)
Initializes a find operations that provides means to find objects by passing a template object.
|
long[] |
findObjectsSingle(AttributeVector template,
int maxObjectCount) |
long |
generateKey(Mechanism mechanism,
AttributeVector template)
/**
Generate a new secret key or a set of domain parameters.
|
PKCS11KeyPair |
generateKeyPair(Mechanism mechanism,
KeyPairTemplate template)
Generate a new public key - private key key-pair and use the set attributes of the template
objects for setting the attributes of the new public key and private key objects.
|
byte[] |
generateRandom(int numberOfBytesToGenerate)
Generates a certain number of random bytes.
|
Object |
getAttrValue(long objectHandle,
long attributeType) |
AttributeVector |
getAttrValues(long objectHandle,
List<Long> attributeTypes) |
AttributeVector |
getAttrValues(long objectHandle,
long... attributeTypes) |
AttributeVector |
getDefaultAttrValues(long objectHandle)
Return the default attributes, but without attributes which contain the sensitive values.
|
AttributeVector |
getDefaultAttrValues(long objectHandle,
boolean withSensitiveVAttributes)
Return the default attributes
|
PKCS11Module |
getModule()
Get the Module which this Session object operates with.
|
byte[] |
getOperationState()
Get the current operation state.
|
long |
getSessionHandle()
Get the handle of this session.
|
SessionInfo |
getSessionInfo()
Get information about this session.
|
String |
getStringAttrValue(long objectHandle,
long attributeType) |
Token |
getToken()
Get the token that created this Session object.
|
void |
login(long userType,
char[] pin)
Logs in the user or the security officer to the session.
|
void |
logout()
Logs out this session.
|
void |
seedRandom(byte[] seed)
Mixes additional seeding material into the random number generator.
|
void |
setAttributeValues(long objectToUpdateHandle,
AttributeVector template)
Gets all present attributes of the given template object and writes them to the object to update
on the token (or in the session).
|
void |
setOperationState(byte[] operationState,
long encryptionKeyHandle,
long authenticationKeyHandle)
Sets the operation state of this session to a previously saved one.
|
void |
setSessionHandle(long sessionHandle) |
byte[] |
sign(byte[] data)
Signs the given data with the key and mechanism given to the signInit method.
|
byte[] |
signFinal()
This method finalizes a signing operation and returns the final result.
|
void |
signInit(Mechanism mechanism,
long keyHandle)
Initializes a new signing operation.
|
int |
signRecover(byte[] in,
byte[] out)
Signs the given data with the key and mechanism given to the signRecoverInit method.
|
int |
signRecover(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Signs the given data with the key and mechanism given to the signRecoverInit method.
|
void |
signRecoverInit(Mechanism mechanism,
long keyHandle)
Initializes a new signing operation for signing with recovery.
|
int |
signRecoverSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
byte[] out) |
int |
signRecoverSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen) |
byte[] |
signSingle(Mechanism mechanism,
long keyHandle,
byte[] data) |
void |
signUpdate(byte[] in)
This method can be used to sign multiple pieces of data; e.g.
|
void |
signUpdate(byte[] in,
int inOfs,
int inLen)
This method can be used to sign multiple pieces of data; e.g.
|
String |
toString()
Returns the string representation of this object.
|
long |
unwrapKey(Mechanism mechanism,
long unwrappingKeyHandle,
byte[] wrappedKey,
AttributeVector keyTemplate)
Unwraps (decrypts) the given encrypted key with the unwrapping key using the given mechanism.
|
void |
verify(byte[] data,
byte[] signature)
Verifies the given signature against the given data with the key and mechanism given to the
verifyInit method.
|
void |
verifyFinal(byte[] signature)
This method finalizes a verification operation.
|
void |
verifyInit(Mechanism mechanism,
long keyHandle)
Initializes a new verification operation.
|
int |
verifyRecover(byte[] in,
byte[] out)
Verifies the given data with the key and mechanism given to the verifyRecoverInit method.
|
int |
verifyRecover(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
Verifies the given data with the key and mechanism given to the verifyRecoverInit method.
|
void |
verifyRecoverInit(Mechanism mechanism,
long keyHandle)
Initializes a new verification operation for verification with data recovery.
|
int |
verifyRecoverSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
byte[] out) |
int |
verifyRecoverSingle(Mechanism mechanism,
long keyHandle,
byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen) |
void |
verifySingle(Mechanism mechanism,
long keyHandle,
byte[] data,
byte[] signature) |
void |
verifyUpdate(byte[] in)
This method can be used to verify a signature with multiple pieces of data; e.g.
|
void |
verifyUpdate(byte[] in,
int inOfs,
int inLen)
This method can be used to verify a signature with multiple pieces of data; e.g.
|
byte[] |
wrapKey(Mechanism mechanism,
long wrappingKeyHandle,
long keyHandle)
Wraps (encrypts) the given key with the wrapping key using the given mechanism.
|
protected Session(Token token, long sessionHandle)
token - The token this session operates with.sessionHandle - The session handle to perform the operations with.public void closeSession()
throws PKCS11Exception
PKCS11Exception - If closing the session failed.public long getSessionHandle()
public SessionInfo getSessionInfo() throws PKCS11Exception
PKCS11Exception - If getting the information failed.public PKCS11Module getModule()
public Token getToken()
public byte[] getOperationState()
throws PKCS11Exception
PKCS11Exception - If saving the state fails or is not possible.public void setOperationState(byte[] operationState,
long encryptionKeyHandle,
long authenticationKeyHandle)
throws PKCS11Exception
operationState - The previously saved state as returned by getOperationState().encryptionKeyHandle - An encryption or decryption key handle, if an encryption or
decryption operation was saved which should be continued, but
the keys could not be saved.authenticationKeyHandle - A signing, verification of MAC key handle, if a signing,
verification or MAC operation needs to be restored that could
not save the key.PKCS11Exception - If restoring the state fails.getOperationState()public void setSessionHandle(long sessionHandle)
public void login(long userType,
char[] pin)
throws PKCS11Exception
userType - CKU_SO for the security officer or CKU_USER to login the user.pin - The PIN. The security officer-PIN or the user-PIN depending on the userType parameter.PKCS11Exception - If login fails.public void logout()
throws PKCS11Exception
PKCS11Exception - If logging out the session fails.public long createObject(AttributeVector template) throws PKCS11Exception
AttributesTemplate desKeyTemplate = new AttributesTemplate().newSecretKey(CKK_DES3);
// the key type is set by the DESSecretKey's constructor, so you need not do it
desKeyTemplate.value(myDesKeyValueAs8BytesLongByteArray)
.token(true)
.private(true);
.encrypt(true);
.decrypt(true);
...
long theCreatedDESKeyObjectHandle = userSession.createObject(desKeyTemplate);
Refer to the PKCS#11 standard to find out what attributes must be set for certain types
of objects to create them on the token.template - The template object that holds all values that the new object on the token should
contain.PKCS11Exception - If the creation of the new object fails. If it fails, the no new object was
created on the token.public long createPrivateKeyObject(AttributeVector template, PublicKey publicKey) throws PKCS11Exception
PKCS11Exceptionpublic long createECPrivateKeyObject(AttributeVector template, byte[] ecPoint) throws PKCS11Exception
PKCS11Exceptionpublic long copyObject(long sourceObjectHandle,
AttributeVector template)
throws PKCS11Exception
sourceObjectHandle - The source object of the copy operation.template - A template object whose attribute values are used for the new object; i.e. they have
higher priority than the attribute values from the source object. May be null; in that
case the new object is just a one-to-one copy of the sourceObject.PKCS11Exception - If copying the object fails for some reason.public void setAttributeValues(long objectToUpdateHandle,
AttributeVector template)
throws PKCS11Exception
objectToUpdateHandle - The attributes of this object get updated.template - Gets all present attributes of this template object and set this
attributes at the objectToUpdate.PKCS11Exception - If updating the attributes fails. All or no attributes are updated.public void destroyObject(long objectHandle)
throws PKCS11Exception
objectHandle - The object handle that should be destroyed.PKCS11Exception - If the object could not be destroyed.public void findObjectsInit(AttributeVector template) throws PKCS11Exception
template - The object that serves as a template for searching. If this object is null, the find
operation will find all objects that this session can see. Notice, that only a user
session will see private objects.PKCS11Exception - If initializing the find operation fails.public long[] findObjects(int maxObjectCount)
throws PKCS11Exception
maxObjectCount - Specifies how many objects to return with this call.PKCS11Exception - A plain PKCS11Exception if something during PKCS11 FindObject went wrong, a
PKCS11Exception with a nested PKCS11Exception if the Exception is raised during
object parsing.public void findObjectsFinal()
throws PKCS11Exception
PKCS11Exception - If finalizing the current find operation was not possible.public long[] findAllObjectsSingle(AttributeVector template) throws PKCS11Exception
PKCS11Exceptionpublic long[] findObjectsSingle(AttributeVector template, int maxObjectCount) throws PKCS11Exception
PKCS11Exceptionpublic void encryptInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.DES_CBC.keyHandle - The decryption key to use.PKCS11Exception - If initializing this operation failed.public int encrypt(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-encrypted dataout - buffer for the encrypted dataPKCS11Exception - If encrypting failed.public int encryptSingle(Mechanism mechanism, long keyHandle, byte[] in, byte[] out) throws PKCS11Exception
PKCS11Exceptionpublic int encrypt(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-encrypted datainOfs - buffer offset of the to-be-encrypted datainLen - length of the to-be-encrypted dataout - buffer for the encrypted dataoutOfs - buffer offset for the encrypted dataoutLen - buffer size for the encrypted dataPKCS11Exception - If encrypting failed.public int encryptSingle(Mechanism mechanism, long keyHandle, byte[] in, int inOfs, int inLen, byte[] out, int outOfs, int outLen) throws PKCS11Exception
PKCS11Exceptionpublic int encryptUpdate(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-encrypted dataout - buffer for the encrypted dataPKCS11Exception - If encrypting the data failed.public int encryptUpdate(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-encrypted datainOfs - buffer offset of the to-be-encrypted datainLen - length of the to-be-encrypted dataout - buffer for the encrypted dataoutOfs - buffer offset for the encrypted dataoutLen - buffer size for the encrypted dataPKCS11Exception - If encrypting the data failed.public int encryptFinal(byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
out - buffer for the encrypted dataoutOfs - buffer offset for the encrypted dataoutLen - buffer size for the encrypted dataPKCS11Exception - If calculating the final result failed.public void decryptInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.DES_CBC.keyHandle - The decryption key to use.PKCS11Exception - If initializing this operation failed.public int decrypt(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-decrypted dataout - buffer for the decrypted dataPKCS11Exception - If decrypting failed.public int decryptSingle(Mechanism mechanism, long keyHandle, byte[] in, byte[] out) throws PKCS11Exception
PKCS11Exceptionpublic int decrypt(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-decrypted datainOfs - buffer offset of the to-be-decrypted datainLen - length of the to-be-decrypted dataout - buffer for the decrypted dataoutOfs - buffer offset for the decrypted dataoutLen - buffer size for the decrypted dataPKCS11Exception - If decrypting failed.public int decryptSingle(Mechanism mechanism, long keyHandle, byte[] in, int inOfs, int inLen, byte[] out, int outOfs, int outLen) throws PKCS11Exception
PKCS11Exceptionpublic int decryptUpdate(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-decrypted dataout - buffer for the decrypted dataPKCS11Exception - If decrypting the data failed.public int decryptUpdate(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-decrypted datainOfs - buffer offset of the to-be-decrypted datainLen - length of the to-be-decrypted dataout - buffer for the decrypted dataoutOfs - buffer offset for the decrypted dataoutLen - buffer size for the decrypted dataPKCS11Exception - If decrypting the data failed.public int decryptFinal(byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
out - buffer for the decrypted dataoutOfs - buffer offset for the decrypted dataoutLen - buffer size for the decrypted dataPKCS11Exception - If calculating the final result failed.public void digestInit(Mechanism mechanism) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.SHA_1.PKCS11Exception - If initializing this operation failed.public int digestFinal(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-digested dataout - buffer for the digested dataPKCS11Exception - If digesting the data failed.public int digestFinal(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-digested datainOfs - buffer offset of the to-be-digested datainLen - length of the to-be-digested dataout - buffer for the digested dataoutOfs - buffer offset for the digested dataoutLen - buffer size for the digested dataPKCS11Exception - If digesting the data failed.public int digest(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-digested dataout - buffer for the digested dataPKCS11Exception - If digesting the data failed.public int digestSingle(Mechanism mechanism, byte[] in, byte[] out) throws PKCS11Exception
PKCS11Exceptionpublic int digest(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-digested datainOfs - buffer offset of the to-be-digested datainLen - length of the to-be-digested dataout - buffer for the digested dataoutOfs - buffer offset for the digested dataoutLen - buffer size for the digested dataPKCS11Exception - If digesting the data failed.public int digestSingle(Mechanism mechanism, byte[] in, int inOfs, int inLen, byte[] out, int outOfs, int outLen) throws PKCS11Exception
PKCS11Exceptionpublic void digestUpdate(byte[] in)
throws PKCS11Exception
in - the to-be-digested dataPKCS11Exception - If digesting the data failed.public void digestUpdate(byte[] in,
int inOfs,
int inLen)
throws PKCS11Exception
in - buffer containing the to-be-digested datainOfs - buffer offset of the to-be-digested datainLen - length of the to-be-digested dataPKCS11Exception - If digesting the data failed.public void digestKey(long keyHandle)
throws PKCS11Exception
keyHandle - The key to digest the value of.PKCS11Exception - If digesting the key failed.public int digestFinal(byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
out - buffer for the message digestoutOfs - buffer offset for the message digestoutLen - buffer size for the message digestPKCS11Exception - If calculating the final message digest failed.public void signInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.RSA_PKCS.keyHandle - The signing key to use.PKCS11Exception - If initializing this operation failed.public byte[] sign(byte[] data)
throws PKCS11Exception
data - The data to sign.PKCS11Exception - If signing the data failed.public byte[] signSingle(Mechanism mechanism, long keyHandle, byte[] data) throws PKCS11Exception
PKCS11Exceptionpublic void signUpdate(byte[] in)
throws PKCS11Exception
in - buffer containing the to-be-signed dataPKCS11Exception - If signing the data failed.public void signUpdate(byte[] in,
int inOfs,
int inLen)
throws PKCS11Exception
in - buffer containing the to-be-signed datainOfs - buffer offset of the to-be-signed datainLen - length of the to-be-signed dataPKCS11Exception - If signing the data failed.public byte[] signFinal()
throws PKCS11Exception
PKCS11Exception - If calculating the final signature value failed.public void signRecoverInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.RSA_9796.keyHandle - The signing key to use.PKCS11Exception - If initializing this operation failed.public int signRecover(byte[] in,
byte[] out)
throws PKCS11Exception
in - buffer containing the to-be-signed dataout - buffer for the signed dataPKCS11Exception - If signing the data failed.public int signRecoverSingle(Mechanism mechanism, long keyHandle, byte[] in, byte[] out) throws PKCS11Exception
PKCS11Exceptionpublic int signRecover(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-signed datainOfs - buffer offset of the to-be-signed datainLen - length of the to-be-signed dataout - buffer for the signed dataoutOfs - buffer offset for the signed dataoutLen - buffer size for the signed dataPKCS11Exception - If signing the data failed.public int signRecoverSingle(Mechanism mechanism, long keyHandle, byte[] in, int inOfs, int inLen, byte[] out, int outOfs, int outLen) throws PKCS11Exception
PKCS11Exceptionpublic void verifyInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.RSA_PKCS.keyHandle - The verification key to use.PKCS11Exception - If initializing this operation failed.public void verify(byte[] data,
byte[] signature)
throws PKCS11Exception
data - The data that was signed.signature - The signature or MAC to verify.PKCS11Exception - If verifying the signature fails. This is also the case, if the signature is
forged.public void verifySingle(Mechanism mechanism, long keyHandle, byte[] data, byte[] signature) throws PKCS11Exception
PKCS11Exceptionpublic void verifyUpdate(byte[] in)
throws PKCS11Exception
in - the to-be-verified dataPKCS11Exception - If verifying (e.g. digesting) the data failed.public void verifyUpdate(byte[] in,
int inOfs,
int inLen)
throws PKCS11Exception
in - buffer containing the to-be-verified datainOfs - buffer offset of the to-be-verified datainLen - length of the to-be-verified dataPKCS11Exception - If verifying (e.g. digesting) the data failed.public void verifyFinal(byte[] signature)
throws PKCS11Exception
signature - The signature value.PKCS11Exception - If verifying the signature fails. This is also the case, if the signature is
forged.public void verifyRecoverInit(Mechanism mechanism, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use; e.g. Mechanism.RSA_9796.keyHandle - The verification key to use.PKCS11Exception - If initializing this operation failed.public int verifyRecover(byte[] in,
byte[] out)
throws PKCS11Exception
in - the to-be-verified dataout - the verified dataPKCS11Exception - If signing the data failed.public int verifyRecoverSingle(Mechanism mechanism, long keyHandle, byte[] in, byte[] out) throws PKCS11Exception
PKCS11Exceptionpublic int verifyRecover(byte[] in,
int inOfs,
int inLen,
byte[] out,
int outOfs,
int outLen)
throws PKCS11Exception
in - buffer containing the to-be-verified datainOfs - buffer offset of the to-be-verified datainLen - length of the to-be-verified dataout - buffer for the verified dataoutOfs - buffer offset for the verified dataoutLen - buffer size for the verified dataPKCS11Exception - If signing the data failed.public int verifyRecoverSingle(Mechanism mechanism, long keyHandle, byte[] in, int inOfs, int inLen, byte[] out, int outOfs, int outLen) throws PKCS11Exception
PKCS11Exceptionpublic long generateKey(Mechanism mechanism, AttributeVector template) throws PKCS11Exception
mechanism - The mechanism to generate a key for; e.g. Mechanism.DES to generate a DES key.template - The template for the new key or domain parameters; e.g. a DESSecretKey object which
has set certain attributes.PKCS11Exception - If generating a new secret key or domain parameters failed.public PKCS11KeyPair generateKeyPair(Mechanism mechanism, KeyPairTemplate template) throws PKCS11Exception
mechanism - The mechanism to generate a key for; e.g. Mechanism.RSA to generate a new RSA
key-pair.template - The template for the new key pair.PKCS11Exception - If generating a new key-pair failed.public byte[] wrapKey(Mechanism mechanism, long wrappingKeyHandle, long keyHandle) throws PKCS11Exception
mechanism - The mechanism to use for wrapping the key.wrappingKeyHandle - The key to use for wrapping (encrypting).keyHandle - The key to wrap (encrypt).PKCS11Exception - If wrapping the key failed.public long unwrapKey(Mechanism mechanism, long unwrappingKeyHandle, byte[] wrappedKey, AttributeVector keyTemplate) throws PKCS11Exception
mechanism - The mechanism to use for unwrapping the key.unwrappingKeyHandle - The key to use for unwrapping (decrypting).wrappedKey - The encrypted key to unwrap (decrypt).keyTemplate - The template for creating the new key object.PKCS11Exception - If unwrapping the key or creating a new key object failed.public long deriveKey(Mechanism mechanism, long baseKeyHandle, AttributeVector template) throws PKCS11Exception
mechanism - The mechanism to use for deriving the new key from the base key.baseKeyHandle - The key to use as base for derivation.template - The template for creating the new key object.PKCS11Exception - If deriving the key or creating a new key object failed.public void seedRandom(byte[] seed)
throws PKCS11Exception
seed - The seed bytes to mix in.PKCS11Exception - If mixing in the seed failed.public byte[] generateRandom(int numberOfBytesToGenerate)
throws PKCS11Exception
numberOfBytesToGenerate - The number of random bytes to generate.PKCS11Exception - If generating random bytes failed.public String toString()
public String getStringAttrValue(long objectHandle, long attributeType) throws PKCS11Exception
PKCS11Exceptionpublic Object getAttrValue(long objectHandle, long attributeType) throws PKCS11Exception
PKCS11Exceptionpublic AttributeVector getAttrValues(long objectHandle, long... attributeTypes) throws PKCS11Exception
PKCS11Exceptionpublic AttributeVector getAttrValues(long objectHandle, List<Long> attributeTypes) throws PKCS11Exception
PKCS11Exceptionpublic AttributeVector getDefaultAttrValues(long objectHandle) throws PKCS11Exception
objectHandle - the object handle.PKCS11Exception - If getting attributes failed.public AttributeVector getDefaultAttrValues(long objectHandle, boolean withSensitiveVAttributes) throws PKCS11Exception
objectHandle - the object handle.withSensitiveVAttributes - whether to get the attributes which contain sensitive values.PKCS11Exception - If getting attributes failed.Copyright © 2023. All rights reserved.