private static String toString(ByteArrayAttribute attr) { try { return new String(attr.getByteArrayValue(), "ASCII"); } catch (UnsupportedEncodingException ex) { return new String(attr.getByteArrayValue()); } } }
@Override public void setValue(Object value) { setByteArrayValue((byte[]) value); }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); modulus = new ByteArrayAttribute(Attribute.MODULUS); publicExponent = new ByteArrayAttribute(Attribute.PUBLIC_EXPONENT); privateExponent = new ByteArrayAttribute(Attribute.PRIVATE_EXPONENT); prime1 = new ByteArrayAttribute(Attribute.PRIME_1); prime2 = new ByteArrayAttribute(Attribute.PRIME_2); exponent1 = new ByteArrayAttribute(Attribute.EXPONENT_1); exponent2 = new ByteArrayAttribute(Attribute.EXPONENT_2); coefficient = new ByteArrayAttribute(Attribute.COEFFICIENT); putAttributesInTable(this); }
privateKeyTemplate.getId().setByteArrayValue(id); publicKeyTemplate.getId().setByteArrayValue(id); certs = new X509Certificate[1]; try { certs[0] = X509Util.parseCert(cert2.getValue().getByteArrayValue()); } catch (CertificateException ex) { throw new P11TokenException("coult not parse certifcate", ex);
/** * 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 X509AttributeCertificate)) { return false; } X509AttributeCertificate other = (X509AttributeCertificate) otherObject; return super.equals(other) && this.owner.equals(other.owner) && this.acIssuer.equals(other.acIssuer) && this.serialNumber.equals(other.serialNumber) && this.attrTypes.equals(other.attrTypes) && this.value.equals(other.value); }
/** * 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 RSAPrivateKey)) { return false; } RSAPrivateKey other = (RSAPrivateKey) otherObject; return super.equals(other) && this.modulus.equals(other.modulus) && this.publicExponent.equals(other.publicExponent) && this.privateExponent.equals(other.privateExponent) && this.prime1.equals(other.prime1) && this.prime2.equals(other.prime2) && this.exponent1.equals(other.exponent1) && this.exponent2.equals(other.exponent2) && this.coefficient.equals(other.coefficient); }
/** * 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 issuer.hashCode(); }
@Override // CHECKSTYLE:OFF protected P11Identity generateDSAKeypair0(final BigInteger p, final BigInteger q, final BigInteger g, final String label, P11NewKeyControl control) throws P11TokenException { // CHECKSTYLE:ON DSAPrivateKey privateKey = new DSAPrivateKey(); DSAPublicKey publicKey = new DSAPublicKey(); setKeyAttributes(label, PKCS11Constants.CKK_DSA, control, publicKey, privateKey); publicKey.getPrime().setByteArrayValue(p.toByteArray()); publicKey.getSubprime().setByteArrayValue(q.toByteArray()); publicKey.getBase().setByteArrayValue(g.toByteArray()); return generateKeyPair(PKCS11Constants.CKM_DSA_KEY_PAIR_GEN, privateKey, publicKey); }
/** * Returns a string representation of the current object. The * output is only for debugging purposes and should not be used for other * purposes. * * @return A string presentation of this object for debugging output. * @preconditions * @postconditions (result <> null) */ @Override public String toString() { StringBuilder sb = new StringBuilder(super.toString()); sb.append("\nValue: "); try { sb.append(new String(value.getByteArrayValue(), "ASCII")); } catch (UnsupportedEncodingException ex) { sb.append(new String(value.getByteArrayValue())); } return sb.toString(); }
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); owner = new ByteArrayAttribute(Attribute.OWNER); acIssuer = new ByteArrayAttribute(Attribute.AC_ISSUER); serialNumber = new ByteArrayAttribute(Attribute.SERIAL_NUMBER); attrTypes = new ByteArrayAttribute(Attribute.ATTR_TYPES); value = new ByteArrayAttribute(Attribute.VALUE); putAttributesInTable(this); }
/** * 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 KEAPublicKey)) { return false; } KEAPublicKey other = (KEAPublicKey) otherObject; return super.equals(other) && this.prime.equals(other.prime) && this.subprime.equals(other.subprime) && this.base.equals(other.base) && this.value.equals(other.value); }
@Override // CHECKSTYLE:SKIP protected P11Identity generateDSAKeypair0(BigInteger p, BigInteger q, BigInteger g, P11NewKeyControl control) throws P11TokenException { long mech = PKCS11Constants.CKM_DSA_KEY_PAIR_GEN; assertMechanismSupported(mech); DSAPrivateKey privateKey = new DSAPrivateKey(); DSAPublicKey publicKey = new DSAPublicKey(); setKeyAttributes(control, publicKey, privateKey); publicKey.getPrime().setByteArrayValue(p.toByteArray()); publicKey.getSubprime().setByteArrayValue(q.toByteArray()); publicKey.getBase().setByteArrayValue(g.toByteArray()); return generateKeyPair(mech, control.getId(), privateKey, publicKey); }
if (p11Key instanceof RSAPublicKey) { RSAPublicKey rsaP11Key = (RSAPublicKey) p11Key; byte[] expBytes = rsaP11Key.getPublicExponent().getByteArrayValue(); BigInteger exp = new BigInteger(1, expBytes); byte[] modBytes = rsaP11Key.getModulus().getByteArrayValue(); BigInteger mod = new BigInteger(1, modBytes); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(mod, exp); DSAPublicKey dsaP11Key = (DSAPublicKey) p11Key; BigInteger prime = new BigInteger(1, dsaP11Key.getPrime().getByteArrayValue()); // p BigInteger subPrime = new BigInteger(1, dsaP11Key.getSubprime().getByteArrayValue()); // q BigInteger base = new BigInteger(1, dsaP11Key.getBase().getByteArrayValue()); // g BigInteger value = new BigInteger(1, dsaP11Key.getValue().getByteArrayValue()); // y DSAPublicKeySpec keySpec = new DSAPublicKeySpec(value, prime, subPrime, base); try { byte[] encodedAlgorithmIdParameters = ecP11Key.getEcdsaParams().getByteArrayValue(); byte[] encodedPoint = DEROctetString.getInstance( ecP11Key.getEcPoint().getByteArrayValue()).getOctets(); try { return KeyUtil.createECPublicKey(encodedAlgorithmIdParameters, encodedPoint);
/** * Allocates the attribute objects for this class and adds them to the * attribute table. * * @preconditions * @postconditions */ @Override protected void allocateAttributes() { super.allocateAttributes(); prime = new ByteArrayAttribute(Attribute.PRIME); subprime = new ByteArrayAttribute(Attribute.SUBPRIME); base = new ByteArrayAttribute(Attribute.BASE); value = new ByteArrayAttribute(Attribute.VALUE); putAttributesInTable(this); }
/** * 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 X942DHPrivateKey)) { return false; } X942DHPrivateKey other = (X942DHPrivateKey) otherObject; return super.equals(other) && this.prime.equals(other.prime) && this.base.equals(other.base) && this.subprime.equals(other.subprime) && this.value.equals(other.value); }
/** * 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 value.hashCode(); }
private static X509PublicKeyCertificate createPkcs11Template(final X509Cert cert, final byte[] keyId, final char[] label) { if (label == null || label.length == 0) { throw new IllegalArgumentException("label must not be null or empty"); } X509PublicKeyCertificate newCertTemp = new X509PublicKeyCertificate(); newCertTemp.getId().setByteArrayValue(keyId); newCertTemp.getLabel().setCharArrayValue(label); newCertTemp.getToken().setBooleanValue(true); newCertTemp.getCertificateType().setLongValue(CertificateType.X_509_PUBLIC_KEY); newCertTemp.getSubject().setByteArrayValue( cert.cert().getSubjectX500Principal().getEncoded()); newCertTemp.getIssuer().setByteArrayValue( cert.cert().getIssuerX500Principal().getEncoded()); newCertTemp.getSerialNumber().setByteArrayValue( cert.cert().getSerialNumber().toByteArray()); newCertTemp.getValue().setByteArrayValue(cert.encodedCert()); return newCertTemp; }
if (p11Key instanceof RSAPublicKey) { RSAPublicKey rsaP11Key = (RSAPublicKey) p11Key; byte[] expBytes = rsaP11Key.getPublicExponent().getByteArrayValue(); BigInteger exp = new BigInteger(1, expBytes); byte[] modBytes = rsaP11Key.getModulus().getByteArrayValue(); BigInteger mod = new BigInteger(1, modBytes); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(mod, exp); DSAPublicKey dsaP11Key = (DSAPublicKey) p11Key; BigInteger prime = new BigInteger(1, dsaP11Key.getPrime().getByteArrayValue()); // p BigInteger subPrime = new BigInteger(1, dsaP11Key.getSubprime().getByteArrayValue()); // q BigInteger base = new BigInteger(1, dsaP11Key.getBase().getByteArrayValue()); // g BigInteger value = new BigInteger(1, dsaP11Key.getValue().getByteArrayValue()); // y DSAPublicKeySpec keySpec = new DSAPublicKeySpec(value, prime, subPrime, base); try { byte[] encodedAlgorithmIdParameters = ecP11Key.getEcdsaParams().getByteArrayValue(); byte[] encodedPoint = DEROctetString.getInstance( ecP11Key.getEcPoint().getByteArrayValue()).getOctets(); try { return KeyUtil.createECPublicKey(encodedAlgorithmIdParameters, encodedPoint);