All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unbound.client.kmip.KMIPSignatureOper Maven / Gradle / Ivy

Go to download

This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi

There is a newer version: 42761
Show newest version
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(); }
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy