/** * Set the attributes of this mechanism attribute array by specifying a * Mechanism[]. Null, is also valid. * A call to this method sets the present flag to true. * * @param value * The MechanismArrayAttribute value to set. May be null. * @preconditions * @postconditions */ @SuppressWarnings("restriction") public void setMechanismAttributeArrayValue(Mechanism[] value) { long[] values = null; if (value != null) { values = new long[value.length]; for (int i = 0; i < value.length; i++) { values[i] = value[i].getMechanismCode(); } } ckAttribute.pValue = values; present = true; }
/** * Get a string representation of the value of this attribute. * * @return A string representation of the value of this attribute. * @preconditions * @postconditions (result <> null) */ @Override protected String getValueString() { StringBuilder sb = new StringBuilder(1024); Mechanism[] allowedMechanisms = getMechanismAttributeArrayValue(); if (allowedMechanisms != null && allowedMechanisms.length > 0) { for (int i = 0; i < allowedMechanisms.length; i++) { sb.append("\n ").append(allowedMechanisms[i].getName()); } return sb.toString(); } else { return "<NULL_PTR>"; } }
/** * Gets the mechanism specified by the given mechanism code. Helper * {@link PKCS11Constants} is available. * * @param pkcs11MechanismCode * the pkcs11 mechanism code * @return the mechanism */ public static Mechanism get(long pkcs11MechanismCode) { return new Mechanism(pkcs11MechanismCode); }
private static CK_MECHANISM toCkMechanism(Mechanism mechanism) { CK_MECHANISM ckMechanism = new CK_MECHANISM(); ckMechanism.mechanism = mechanism.getMechanismCode(); Params params = mechanism.getParams(); ckMechanism.pParameter = (params != null) ? params.getPKCS11ParamsObject() : null; return ckMechanism; }
session.digestInit(Mechanism.get(mechanism)); session.digestKey((SecretKey) signingKey); byte[] digest = new byte[digestLen];
private static Mechanism getMechanism(final long mechanism, final P11Params parameters) throws P11TokenException { Mechanism ret = Mechanism.get(mechanism); if (parameters == null) { return ret; } if (parameters instanceof P11RSAPkcsPssParams) { P11RSAPkcsPssParams param = (P11RSAPkcsPssParams) parameters; RSAPkcsPssParameters paramObj = new RSAPkcsPssParameters( Mechanism.get(param.hashAlgorithm()), param.maskGenerationFunction(), param.saltLength()); ret.setParameters(paramObj); } else { throw new P11TokenException("unknown P11Parameters " + parameters.getClass().getName()); } return ret; }
private static Mechanism getMechanism(long mechanism, P11Params parameters) throws P11TokenException { Mechanism ret = Mechanism.get(mechanism); if (parameters == null) { return ret; } Params paramObj; if (parameters instanceof P11Params.P11RSAPkcsPssParams) { P11Params.P11RSAPkcsPssParams param = (P11Params.P11RSAPkcsPssParams) parameters; paramObj = new RSAPkcsPssParams(Mechanism.get(param.getHashAlgorithm()), param.getMaskGenerationFunction(), param.getSaltLength()); } else if (parameters instanceof P11Params.P11ByteArrayParams) { paramObj = new OpaqueParams(((P11Params.P11ByteArrayParams) parameters).getBytes()); } else if (parameters instanceof P11Params.P11IVParams) { paramObj = new IVParams(((P11Params.P11IVParams) parameters).getIV()); } else { throw new P11TokenException("unknown P11Parameters " + parameters.getClass().getName()); } if (paramObj != null) { ret.setParams(paramObj); } return ret; }
/** * The overriding of this method should ensure that the objects of this * class work correctly in a hashtable. * * @return The hash code of this object. * @preconditions * @postconditions */ @Override public int hashCode() { return hashAlg.hashCode() ^ ((int) mgf); }
/** * Compares all member variables of this object with the other object. * Returns only true, if all are equal in both objects. * * @param otherObject * The other object to compare to. * @return True, if other is an instance of this class and all member * variables of both objects are equal. False, otherwise. * @preconditions * @postconditions */ @Override public boolean equals(Object otherObject) { if (this == otherObject) { return true; } else if (!(otherObject instanceof RSAPkcsParams)) { return false; } RSAPkcsParams other = (RSAPkcsParams) otherObject; return this.hashAlg.equals(other.hashAlg) && (this.mgf == other.mgf); }
throws TokenException { CK_MECHANISM ckMechanism = toCkMechanism(mechanism); Params params = mechanism.getParams(); CK_ATTRIBUTE[] ckAttributes = PKCS11Object.getSetAttributes(template);
Mechanism mechanismObj = Mechanism.get(mechanism);
/** * Set the mechanism value of this attribute. * <code>null</code>, is also valid. * A call to this method sets the present flag to true. * * @param mechanism * The mechanism value to set. May be <code>null</code>. * @preconditions * @postconditions */ @SuppressWarnings("restriction") public void setMechanism(Mechanism mechanism) { ckAttribute.pValue = (mechanism != null) ? new Long(mechanism.getMechanismCode()) : null; present = true; }
keypair = session.generateKeyPair(Mechanism.get(mech), publicKeyTemplate, privateKeyTemplate);
/** * Get the long value of this attribute. Null, is also possible. * * @return The long value of this attribute or null. * @preconditions * @postconditions */ @SuppressWarnings("restriction") public Mechanism getMechanism() { return ((ckAttribute != null) && (ckAttribute.pValue != null)) ? new Mechanism(((Long) ckAttribute.pValue).longValue()) : null; }
/** * Get this parameters object as an object of the CK_RSA_PKCS_PSS_PARAMS * class. * * @return This object as a CK_RSA_PKCS_PSS_PARAMS object. * @preconditions * @postconditions (result <> null) */ @Override public Object getPKCS11ParamsObject() { CK_RSA_PKCS_PSS_PARAMS params = new CK_RSA_PKCS_PSS_PARAMS(); params.hashAlg = hashAlg.getMechanismCode(); params.mgf = mgf; params.sLen = saltLength; return params; }
publicKey.getId().setByteArrayValue(id); try { keypair = session.generateKeyPair(Mechanism.get(mech), publicKey, privateKey); } catch (TokenException ex) { throw new P11TokenException("could not generate keypair "
/** * Get the mechanism attribute array value of this attribute as Mechanism[]. * Null, is also possible. * * @return The mechanism attribute array value of this attribute or null. * @preconditions * @postconditions */ @SuppressWarnings("restriction") public Mechanism[] getMechanismAttributeArrayValue() { Mechanism[] mechanisms = null; if (ckAttribute.pValue != null) { long[] values = (long[]) ckAttribute.pValue; if (values != null && values.length > 0) { mechanisms = new Mechanism[values.length]; for (int i = 0; i < values.length; i++) { Mechanism mechanism = new Mechanism(values[i]); mechanisms[i] = mechanism; } } } return mechanisms; }
/** * Get this parameters object as an object of the CK_RSA_PKCS_OAEP_PARAMS * class. * * @return This object as a CK_RSA_PKCS_OAEP_PARAMS object. * @preconditions * @postconditions (result <> null) */ @Override public Object getPKCS11ParamsObject() { CK_RSA_PKCS_OAEP_PARAMS params = new CK_RSA_PKCS_OAEP_PARAMS(); params.hashAlg = hashAlg.getMechanismCode(); params.mgf = mgf; params.source = source; params.pSourceData = sourceData; return params; }