/** * Encode an {@code AlgorithmIdentifier} using the given DER encoder. The ASN.1 definition of {@code AlgorithmIdentifier} is: * * <pre> * AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { * algorithm ALGORITHM.&id({IOSet}), * parameters ALGORITHM.&Type({IOSet}{{@literal @}algorithm}) OPTIONAL * } * </pre> * * @param encoder the DER encoder */ private void encodeAlgorithmIdentifier(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeObjectIdentifier(signatureAlgorithmOid); if (signingKey.getAlgorithm().equals("RSA")) { // Include the NULL parameter for RSA based signature algorithms only, as per RFC 3279 (http://www.ietf.org/rfc/rfc3279) encoder.encodeNull(); } encoder.endSequence(); }
/** * <p> * Encode an {@code AlgorithmIdentifier} without any parameters using the given * DER encoder and object identifier, where {@code AlgorithmIdentifier} is defined as: * * <pre> * AlgorithmIdentifier ::= SEQUENCE { * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL * } * </pre> * </p> * * @param encoder the DER encoder * @param objectIdentifier the object identifier for the algorithm * @param omitParametersField {@code true} if the parameters field should be ommitted in * the encoding and {@code false} otherwise * @throws ASN1Exception if the given object identifier is invalid */ public static void encodeAlgorithmIdentifier(final DEREncoder encoder, String objectIdentifier, boolean omitParametersField) throws ASN1Exception { encoder.startSequence(); encoder.encodeObjectIdentifier(objectIdentifier); if (!omitParametersField) { encoder.encodeNull(); } encoder.endSequence(); }
derEncoder.encodeObjectIdentifier(signatureAlgorithmOid);
/** * <p> * Create an {@code OtherName} that is defined as: * * <pre> * OtherName ::= SEQUENCE { * type-id OBJECT IDENTIFIER, * value [0] EXPLICIT ANY DEFINED BY type-id } * </pre> * </p> * * @param typeId the object identifier for this name * @param encodedValue the DER encoded value for this name * @throws ASN1Exception if {@code encodedValue} is not DER encoded */ public OtherName(final String typeId, final byte[] encodedValue) throws ASN1Exception { super(OTHER_NAME); this.typeId = typeId; this.encodedValue = encodedValue; final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.encodeObjectIdentifier(typeId); encoder.writeEncoded(encodedValue); encoder.endSequence(); encodedName = encoder.getEncoded(); }
/** * Encode {@code Attributes} using the given DER encoder. The ASN.1 definition of {@code Attributes} is: * * <pre> * Attributes ::= SET OF Attribute * * Attribute :: SEQUENCE { * type AttributeType, * values SET OF AttributeValue * } * * AttributeType ::= OBJECT IDENTIFIER * AttributeValue ::= ANY defined by type * </pre> * * @param encoder the DER encoder */ private void encodeAttributes(final DEREncoder encoder) { encoder.startSetOf(); encoder.startSequence(); // extensionRequest attribute encoder.encodeObjectIdentifier(ASN1.OID_EXTENSION_REQUEST); encoder.startSetOf(); encodeExtensionRequest(encoder); encoder.endSetOf(); encoder.endSequence(); encoder.endSetOf(); }
/** * Encode an {@code Extension} using the given DER encoder. The ASN.1 definition of {@code Extension} is: * * <pre> * Extension ::= SEQUENCE { * extensionId OBJECT IDENTIFIER, * critical BOOLEAN DEFAULT FALSE, * extensionValue OCTET STRING * } * </pre> * * @param encoder the DER encoder * @param extension the X.509 certificate extension */ private static void encodeExtension(final DEREncoder encoder, final X509CertificateExtension extension) { encoder.startSequence(); encoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) { encoder.encodeBoolean(true); } DEREncoder extensionEncoder = new DEREncoder(); extension.encodeTo(extensionEncoder); encoder.encodeOctetString(extensionEncoder.getEncoded()); encoder.endSequence(); }
derEncoder.encodeInteger(serialNumber); derEncoder.encodeObjectIdentifier(signatureAlgorithmOid); for (X509CertificateExtension extension : extensionsByOid.values()) { derEncoder.startSequence(); derEncoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) derEncoder.encodeBoolean(true); final DEREncoder subEncoder = new DEREncoder();
/** * Encode an {@code AlgorithmIdentifier} using the given DER encoder. The ASN.1 definition of {@code AlgorithmIdentifier} is: * * <pre> * AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { * algorithm ALGORITHM.&id({IOSet}), * parameters ALGORITHM.&Type({IOSet}{{@literal @}algorithm}) OPTIONAL * } * </pre> * * @param encoder the DER encoder */ private void encodeAlgorithmIdentifier(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeObjectIdentifier(signatureAlgorithmOid); if (signingKey.getAlgorithm().equals("RSA")) { // Include the NULL parameter for RSA based signature algorithms only, as per RFC 3279 (http://www.ietf.org/rfc/rfc3279) encoder.encodeNull(); } encoder.endSequence(); }
/** * Encode an {@code AlgorithmIdentifier} using the given DER encoder. The ASN.1 definition of {@code AlgorithmIdentifier} is: * * <pre> * AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { * algorithm ALGORITHM.&id({IOSet}), * parameters ALGORITHM.&Type({IOSet}{{@literal @}algorithm}) OPTIONAL * } * </pre> * * @param encoder the DER encoder */ private void encodeAlgorithmIdentifier(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeObjectIdentifier(signatureAlgorithmOid); if (signingKey.getAlgorithm().equals("RSA")) { // Include the NULL parameter for RSA based signature algorithms only, as per RFC 3279 (http://www.ietf.org/rfc/rfc3279) encoder.encodeNull(); } encoder.endSequence(); }
/** * Encode an {@code AlgorithmIdentifier} using the given DER encoder. The ASN.1 definition of {@code AlgorithmIdentifier} is: * * <pre> * AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { * algorithm ALGORITHM.&id({IOSet}), * parameters ALGORITHM.&Type({IOSet}{{@literal @}algorithm}) OPTIONAL * } * </pre> * * @param encoder the DER encoder */ private void encodeAlgorithmIdentifier(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeObjectIdentifier(signatureAlgorithmOid); if (signingKey.getAlgorithm().equals("RSA")) { // Include the NULL parameter for RSA based signature algorithms only, as per RFC 3279 (http://www.ietf.org/rfc/rfc3279) encoder.encodeNull(); } encoder.endSequence(); }
/** * <p> * Encode an {@code AlgorithmIdentifier} without any parameters using the given * DER encoder and object identifier, where {@code AlgorithmIdentifier} is defined as: * * <pre> * AlgorithmIdentifier ::= SEQUENCE { * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL * } * </pre> * </p> * * @param encoder the DER encoder * @param objectIdentifier the object identifier for the algorithm * @param omitParametersField {@code true} if the parameters field should be ommitted in * the encoding and {@code false} otherwise * @throws ASN1Exception if the given object identifier is invalid */ public static void encodeAlgorithmIdentifier(final DEREncoder encoder, String objectIdentifier, boolean omitParametersField) throws ASN1Exception { encoder.startSequence(); encoder.encodeObjectIdentifier(objectIdentifier); if (!omitParametersField) { encoder.encodeNull(); } encoder.endSequence(); }
/** * <p> * Encode an {@code AlgorithmIdentifier} without any parameters using the given * DER encoder and object identifier, where {@code AlgorithmIdentifier} is defined as: * * <pre> * AlgorithmIdentifier ::= SEQUENCE { * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL * } * </pre> * </p> * * @param encoder the DER encoder * @param objectIdentifier the object identifier for the algorithm * @param omitParametersField {@code true} if the parameters field should be ommitted in * the encoding and {@code false} otherwise * @throws ASN1Exception if the given object identifier is invalid */ public static void encodeAlgorithmIdentifier(final DEREncoder encoder, String objectIdentifier, boolean omitParametersField) throws ASN1Exception { encoder.startSequence(); encoder.encodeObjectIdentifier(objectIdentifier); if (!omitParametersField) { encoder.encodeNull(); } encoder.endSequence(); }
derEncoder.encodeObjectIdentifier(signatureAlgorithmOid);
/** * <p> * Create an {@code OtherName} that is defined as: * * <pre> * OtherName ::= SEQUENCE { * type-id OBJECT IDENTIFIER, * value [0] EXPLICIT ANY DEFINED BY type-id } * </pre> * </p> * * @param typeId the object identifier for this name * @param encodedValue the DER encoded value for this name * @throws ASN1Exception if {@code encodedValue} is not DER encoded */ public OtherName(final String typeId, final byte[] encodedValue) throws ASN1Exception { super(OTHER_NAME); this.typeId = typeId; this.encodedValue = encodedValue; final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.encodeObjectIdentifier(typeId); encoder.writeEncoded(encodedValue); encoder.endSequence(); encodedName = encoder.getEncoded(); }
/** * <p> * Create an {@code OtherName} that is defined as: * * <pre> * OtherName ::= SEQUENCE { * type-id OBJECT IDENTIFIER, * value [0] EXPLICIT ANY DEFINED BY type-id } * </pre> * </p> * * @param typeId the object identifier for this name * @param encodedValue the DER encoded value for this name * @throws ASN1Exception if {@code encodedValue} is not DER encoded */ public OtherName(final String typeId, final byte[] encodedValue) throws ASN1Exception { super(OTHER_NAME); this.typeId = typeId; this.encodedValue = encodedValue; final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.encodeObjectIdentifier(typeId); encoder.writeEncoded(encodedValue); encoder.endSequence(); encodedName = encoder.getEncoded(); }
/** * Encode {@code Attributes} using the given DER encoder. The ASN.1 definition of {@code Attributes} is: * * <pre> * Attributes ::= SET OF Attribute * * Attribute :: SEQUENCE { * type AttributeType, * values SET OF AttributeValue * } * * AttributeType ::= OBJECT IDENTIFIER * AttributeValue ::= ANY defined by type * </pre> * * @param encoder the DER encoder */ private void encodeAttributes(final DEREncoder encoder) { encoder.startSetOf(); encoder.startSequence(); // extensionRequest attribute encoder.encodeObjectIdentifier(ASN1.OID_EXTENSION_REQUEST); encoder.startSetOf(); encodeExtensionRequest(encoder); encoder.endSetOf(); encoder.endSequence(); encoder.endSetOf(); }
/** * Encode {@code Attributes} using the given DER encoder. The ASN.1 definition of {@code Attributes} is: * * <pre> * Attributes ::= SET OF Attribute * * Attribute :: SEQUENCE { * type AttributeType, * values SET OF AttributeValue * } * * AttributeType ::= OBJECT IDENTIFIER * AttributeValue ::= ANY defined by type * </pre> * * @param encoder the DER encoder */ private void encodeAttributes(final DEREncoder encoder) { encoder.startSetOf(); encoder.startSequence(); // extensionRequest attribute encoder.encodeObjectIdentifier(ASN1.OID_EXTENSION_REQUEST); encoder.startSetOf(); encodeExtensionRequest(encoder); encoder.endSetOf(); encoder.endSequence(); encoder.endSetOf(); }
/** * Encode an {@code Extension} using the given DER encoder. The ASN.1 definition of {@code Extension} is: * * <pre> * Extension ::= SEQUENCE { * extensionId OBJECT IDENTIFIER, * critical BOOLEAN DEFAULT FALSE, * extensionValue OCTET STRING * } * </pre> * * @param encoder the DER encoder * @param extension the X.509 certificate extension */ private static void encodeExtension(final DEREncoder encoder, final X509CertificateExtension extension) { encoder.startSequence(); encoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) { encoder.encodeBoolean(true); } DEREncoder extensionEncoder = new DEREncoder(); extension.encodeTo(extensionEncoder); encoder.encodeOctetString(extensionEncoder.getEncoded()); encoder.endSequence(); }
/** * Encode an {@code Extension} using the given DER encoder. The ASN.1 definition of {@code Extension} is: * * <pre> * Extension ::= SEQUENCE { * extensionId OBJECT IDENTIFIER, * critical BOOLEAN DEFAULT FALSE, * extensionValue OCTET STRING * } * </pre> * * @param encoder the DER encoder * @param extension the X.509 certificate extension */ private static void encodeExtension(final DEREncoder encoder, final X509CertificateExtension extension) { encoder.startSequence(); encoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) { encoder.encodeBoolean(true); } DEREncoder extensionEncoder = new DEREncoder(); extension.encodeTo(extensionEncoder); encoder.encodeOctetString(extensionEncoder.getEncoded()); encoder.endSequence(); }
/** * Encode an {@code Extension} using the given DER encoder. The ASN.1 definition of {@code Extension} is: * * <pre> * Extension ::= SEQUENCE { * extensionId OBJECT IDENTIFIER, * critical BOOLEAN DEFAULT FALSE, * extensionValue OCTET STRING * } * </pre> * * @param encoder the DER encoder * @param extension the X.509 certificate extension */ private static void encodeExtension(final DEREncoder encoder, final X509CertificateExtension extension) { encoder.startSequence(); encoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) { encoder.encodeBoolean(true); } DEREncoder extensionEncoder = new DEREncoder(); extension.encodeTo(extensionEncoder); encoder.encodeOctetString(extensionEncoder.getEncoded()); encoder.endSequence(); }