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

com.unbound.client.pkcs11.PKCS11ECPRFKey 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.pkcs11;

import com.dyadicsec.cryptoki.*;
import com.unbound.client.ECPRFKey;
import com.unbound.client.ObjectType;
import com.unbound.provider.KeyParameters;

import java.security.ProviderException;
import java.util.ArrayList;

import static com.dyadicsec.cryptoki.CK.*;
import static com.dyadicsec.cryptoki.CK.CKA_WRAP_WITH_TRUSTED;

public class PKCS11ECPRFKey extends PKCS11Object implements ECPRFKey
{
  PKCS11ECPRFKey(PKCS11Session session, int handle)
  {
    super(ObjectType.ECPrf, handle);
    read(session);
  }

  static ArrayList getNewTemplate(String name, KeyParameters kp)
  {
    if (name==null && kp!=null) name = kp.getName();
    ArrayList t = new ArrayList();
    try
    {
      t.add(new CK_ATTRIBUTE(CKA_TOKEN, kp==null || kp.isToken()));
      t.add(new CK_ATTRIBUTE(CKA_CLASS, CKO_PRIVATE_KEY));
      t.add(new CK_ATTRIBUTE(CKA_KEY_TYPE, DYCKK_ADV_PRF));

      if (name!=null) t.add(new CK_ATTRIBUTE(CKA_ID, strToId(name)));

      if (kp!=null)
      {
        if (kp.isSetEncrypt()) t.add(new CK_ATTRIBUTE(CKA_ENCRYPT, kp.isAllowEncrypt()));
        if (kp.isSetDecrypt()) t.add(new CK_ATTRIBUTE(CKA_DECRYPT, kp.isAllowDecrypt()));
        if (kp.isSetDerive()) t.add(new CK_ATTRIBUTE(CKA_DERIVE, kp.isAllowDerive()));
        makeExportLevel(t, kp);
      }
    }
    catch (CKR_Exception e)
    {
      throw new ProviderException(e);
    }
    return t;
  }

  static PKCS11ECPRFKey generate(PKCS11Session session, String name, KeyParameters kp)
  {
    try
    {
      ArrayList t = getNewTemplate(name, kp);
      int handle = Library.C_GenerateKey(session.getHandle(), new CK_MECHANISM(DYCKM_PRF_KEY_GEN), getAttrs(t));
		  return new PKCS11ECPRFKey(session, handle);
    }
    catch (CKR_Exception e) { throw new ProviderException(e); }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy