com.unbound.client.kmip.KMIPSignatureOper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.unbound.client.kmip;
import com.unbound.client.SignatureMode;
import com.unbound.client.SignatureOper;
import com.unbound.common.Log;
import com.unbound.common.crypto.EC;
import com.unbound.kmip.attribute.CryptoParams;
import com.unbound.kmip.request.SignRequest;
import com.unbound.kmip.response.SignResponse;
public class KMIPSignatureOper extends SignatureOper
{
private long getKeyUid() { return ((KMIPObject)keyObject).uid; }
private KMIPSession getKmipSession() { return (KMIPSession)session; }
private void setCryptoParams(SignRequest req)
{
req.params = new CryptoParams();
req.params.cryptoAlg = ((KMIPObject)keyObject).type.getKmipAlg();
req.params.signingAlg = mode.getKmipSigAlg(hashType);
if (hashType!=null) req.params.hashingAlg = hashType.getKmipHashAlg();
req.params.padding = mode.getKmipPadding();
}
@Override
protected byte[] hwSign(byte[] in)
{
int outLen = 0;
Log log = Log.func("KMIPCryptoOperation.sign").log("inLen", in.length).end(); try
{
SignRequest req = new SignRequest();
req.uid = KMIPObject.uidToStr(getKeyUid());
req.data = in;
setCryptoParams(req);
SignResponse resp = (SignResponse)getKmipSession().transmit(req);
byte[] out = resp.data;
if (mode == SignatureMode.ECDSA)
{
EC.Curve curve = ((KMIPECPrivateKey)keyObject).getCurve();
out = curve.sigBinToDer(out);
}
outLen = out.length;
return out;
}
catch (Exception e) { log.failed(e); throw e; } finally { log.leavePrint().log("outLen", outLen).end(); }
}
}