use of org.openecard.mdlw.sal.cryptoki.CK_RSA_PKCS_PSS_PARAMS in project open-ecard by ecsec.
the class MwPrivateKey method sign.
/**
* Signs Data with a {@link Mechanism}.
* Returns the signed Data in an byte array.
*
* @param mechanism
* @param data
* @return
* @throws CryptokiException
*/
public byte[] sign(long mechanism, byte[] data) throws CryptokiException {
Pointer paramsPtr;
NativeLong paramsPtrSize;
if (isPSSAlg((int) mechanism)) {
// only execute with PSS algorithm
// determine parameters for PKCS#11 PSS
LOG.debug("Preparing PSS Parameters.");
NativeLong hashAlg = new NativeLong(getHashAlg((int) mechanism, data), true);
NativeLong mgfAlg = new NativeLong(getMgf1Alg(hashAlg.intValue()), true);
NativeLong sLen = new NativeLong(getHashLen(hashAlg.intValue()), true);
CK_RSA_PKCS_PSS_PARAMS pssParams = new CK_RSA_PKCS_PSS_PARAMS(hashAlg, mgfAlg, sLen);
pssParams.write();
paramsPtr = pssParams.getPointer();
paramsPtrSize = new NativeLong(pssParams.size(), true);
} else {
paramsPtr = Pointer.NULL;
paramsPtrSize = new NativeLong(0, true);
}
CK_MECHANISM pMechanism = new CK_MECHANISM(new NativeLong(mechanism, true), paramsPtr, paramsPtrSize);
try (MiddleWareWrapper.LockedMiddlewareWrapper lmw = mw.lock()) {
lmw.signInit(session.getSessionId(), pMechanism, objectHandle);
return lmw.sign(session.getSessionId(), data);
} catch (InterruptedException ex) {
throw new ThreadTerminateException("Thread interrupted while waiting for Middleware lock.", ex);
}
}
Aggregations