/** * Encode an ASN.1 set of certificates using the given DER encoder and the * given {@code X509Certificate} chain. * * @param encoder the DER encoder * @param certChain the X.509 certificate chain to encode * @throws ASN1Exception if an error occurs while encoding the given certificate chain */ public static void encodeX509CertificateChain(final DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception { try { int chainSize = certChain.length; encoder.startSetOf(); for (int i = 0; i < chainSize; i++) { encoder.writeEncoded(certChain[i].getEncoded()); } encoder.endSetOf(); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } }
/** * Encode a {@code CertificationRequestInfo} using the given DER encoder. The ASN.1 definition of {@code CertificationRequestInfo} is: * * <pre> * CertificationRequestInfo ::= SEQUENCE { * version INTEGER { v1(0) } (v1,...), * subject Name, * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, * attributes [0] Attributes{{ CRIAttributes }} * } * </pre> * * @param encoder the DER encoder */ private void encodeCertificationRequestInfo(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeInteger(VERSION); encoder.writeEncoded(subjectDn.getEncoded()); encoder.writeEncoded(publicKey.getEncoded()); // subjectPKInfo encoder.encodeImplicit(0); encodeAttributes(encoder); encoder.endSequence(); }
/** * Recompute and restore the initial context token header for the given token. * * @param token the initial context token without the token header * @return the initial context token with the token header restored * @throws ASN1Exception if the mechanism OID cannot be DER encoded */ private byte[] restoreTokenHeader(byte[] token) throws ASN1Exception { final DEREncoder encoder = new DEREncoder(); encoder.encodeImplicit(APPLICATION_SPECIFIC_MASK, 0); encoder.startSequence(); try { encoder.writeEncoded(mechanism.getDER()); } catch (GSSException e) { throw new ASN1Exception(e); } encoder.writeEncoded(token); encoder.endSequence(); return encoder.getEncoded(); }
derEncoder.writeEncoded(tbsCertificate);
encoder.writeEncoded(tbsEncoder.getEncoded()); encodeAlgorithmIdentifier(encoder); encoder.encodeBitString(signatureBytes);
/** * <p> * Create an {@code EDIPartyName} that is defined as: * * <pre> * EDIPartyName ::= SEQUENCE { * nameAssigner [0] DirectoryString OPTIONAL, * partyName [1] DirectoryString } * </pre> * </p> * * @param encoded the DER encoded form of the name or the value bytes from the DER encoded form of the name, as a byte array * @param valueBytesOnly whether or not {@code encoded} contains only the value bytes from the DER encoded form of the name * @throws ASN1Exception if {@code encoded} is not DER encoded */ public EDIPartyName(final byte[] encoded, final boolean valueBytesOnly) throws ASN1Exception { super(EDI_PARTY_NAME); if (valueBytesOnly) { final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.writeEncoded(encoded); encoder.endSequence(); encodedName = encoder.getEncoded(); } else { encodedName = encoded; } }
/** * <p> * Create an {@code X400Address} that is defined as: * * <pre> * X400Address ::= SEQUENCE { * built-in-standard-attributes BuiltInStandardAttributes, * built-in-domain-defined-attributes BuiltInDomainDefinedAttributes OPTIONAL, * -- see also teletex-domain-defined-attributes * extension-attributes ExtensionAttributes OPTIONAL } * </pre> * </p> * * @param encoded the DER encoded form of the name or the value bytes from the DER encoded form of the name, as a byte array * @param valueBytesOnly whether or not {@code encoded} contains only the value bytes from the DER encoded form of the name * @throws ASN1Exception if {@code encoded} is not DER encoded */ public X400Address(final byte[] encoded, final boolean valueBytesOnly) throws ASN1Exception { super(X400_ADDRESS); if (valueBytesOnly) { final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.writeEncoded(encoded); encoder.endSequence(); encodedName = encoder.getEncoded(); } else { encodedName = encoded; } }
/** * <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(); }
derEncoder.writeEncoded(issuerDn.getEncoded()); // already a SEQUENCE of SET of SEQUENCE of { OBJECT IDENTIFIER, ANY } if (subjectDn != null) derEncoder.writeEncoded(subjectDn.getEncoded()); // already a SEQUENCE of SET of SEQUENCE of { OBJECT IDENTIFIER, ANY } throw log.invalidKeyForCert(publicKeyAlgorithm, e); derEncoder.writeEncoded(keySpec.getEncoded()); // SubjectPublicKeyInfo
final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.writeEncoded(publicSpec.getEncoded()); encoder.writeEncoded(privateSpec.getEncoded()); encoder.endSequence(); entry = new KeyStore.SecretKeyEntry(new SecretKeySpec(encoder.getEncoded(), DATA_OID)); encoder.startSequence(); for (X509Certificate x509Certificate : x509Certificates) { encoder.writeEncoded(x509Certificate.getEncoded());
/** * Encode an ASN.1 set of certificates using the given DER encoder and the * given {@code X509Certificate} chain. * * @param encoder the DER encoder * @param certChain the X.509 certificate chain to encode * @throws ASN1Exception if an error occurs while encoding the given certificate chain */ public static void encodeX509CertificateChain(final DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception { try { int chainSize = certChain.length; encoder.startSetOf(); for (int i = 0; i < chainSize; i++) { encoder.writeEncoded(certChain[i].getEncoded()); } encoder.endSetOf(); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } }
/** * Encode an ASN.1 set of certificates using the given DER encoder and the * given {@code X509Certificate} chain. * * @param encoder the DER encoder * @param certChain the X.509 certificate chain to encode * @throws ASN1Exception if an error occurs while encoding the given certificate chain */ public static void encodeX509CertificateChain(final DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception { try { int chainSize = certChain.length; encoder.startSetOf(); for (int i = 0; i < chainSize; i++) { encoder.writeEncoded(certChain[i].getEncoded()); } encoder.endSetOf(); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } }
/** * Encode an ASN.1 set of certificates using the given DER encoder and the * given {@code X509Certificate} chain. * * @param encoder the DER encoder * @param certChain the X.509 certificate chain to encode * @throws ASN1Exception if an error occurs while encoding the given certificate chain */ public static void encodeX509CertificateChain(final DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception { try { int chainSize = certChain.length; encoder.startSetOf(); for (int i = 0; i < chainSize; i++) { encoder.writeEncoded(certChain[i].getEncoded()); } encoder.endSetOf(); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } }
/** * Encode a {@code CertificationRequestInfo} using the given DER encoder. The ASN.1 definition of {@code CertificationRequestInfo} is: * * <pre> * CertificationRequestInfo ::= SEQUENCE { * version INTEGER { v1(0) } (v1,...), * subject Name, * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, * attributes [0] Attributes{{ CRIAttributes }} * } * </pre> * * @param encoder the DER encoder */ private void encodeCertificationRequestInfo(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeInteger(VERSION); encoder.writeEncoded(subjectDn.getEncoded()); encoder.writeEncoded(publicKey.getEncoded()); // subjectPKInfo encoder.encodeImplicit(0); encodeAttributes(encoder); encoder.endSequence(); }
/** * Encode a {@code CertificationRequestInfo} using the given DER encoder. The ASN.1 definition of {@code CertificationRequestInfo} is: * * <pre> * CertificationRequestInfo ::= SEQUENCE { * version INTEGER { v1(0) } (v1,...), * subject Name, * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, * attributes [0] Attributes{{ CRIAttributes }} * } * </pre> * * @param encoder the DER encoder */ private void encodeCertificationRequestInfo(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeInteger(VERSION); encoder.writeEncoded(subjectDn.getEncoded()); encoder.writeEncoded(publicKey.getEncoded()); // subjectPKInfo encoder.encodeImplicit(0); encodeAttributes(encoder); encoder.endSequence(); }
/** * Encode a {@code CertificationRequestInfo} using the given DER encoder. The ASN.1 definition of {@code CertificationRequestInfo} is: * * <pre> * CertificationRequestInfo ::= SEQUENCE { * version INTEGER { v1(0) } (v1,...), * subject Name, * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, * attributes [0] Attributes{{ CRIAttributes }} * } * </pre> * * @param encoder the DER encoder */ private void encodeCertificationRequestInfo(final DEREncoder encoder) { encoder.startSequence(); encoder.encodeInteger(VERSION); encoder.writeEncoded(subjectDn.getEncoded()); encoder.writeEncoded(publicKey.getEncoded()); // subjectPKInfo encoder.encodeImplicit(0); encodeAttributes(encoder); encoder.endSequence(); }
/** * Recompute and restore the initial context token header for the given token. * * @param token the initial context token without the token header * @return the initial context token with the token header restored * @throws ASN1Exception if the mechanism OID cannot be DER encoded */ private byte[] restoreTokenHeader(byte[] token) throws ASN1Exception { final DEREncoder encoder = new DEREncoder(); encoder.encodeImplicit(APPLICATION_SPECIFIC_MASK, 0); encoder.startSequence(); try { encoder.writeEncoded(mechanism.getDER()); } catch (GSSException e) { throw new ASN1Exception(e); } encoder.writeEncoded(token); encoder.endSequence(); return encoder.getEncoded(); }
/** * Recompute and restore the initial context token header for the given token. * * @param token the initial context token without the token header * @return the initial context token with the token header restored * @throws ASN1Exception if the mechanism OID cannot be DER encoded */ private byte[] restoreTokenHeader(byte[] token) throws ASN1Exception { final DEREncoder encoder = new DEREncoder(); encoder.encodeImplicit(APPLICATION_SPECIFIC_MASK, 0); encoder.startSequence(); try { encoder.writeEncoded(mechanism.getDER()); } catch (GSSException e) { throw new ASN1Exception(e); } encoder.writeEncoded(token); encoder.endSequence(); return encoder.getEncoded(); }
/** * Recompute and restore the initial context token header for the given token. * * @param token the initial context token without the token header * @return the initial context token with the token header restored * @throws ASN1Exception if the mechanism OID cannot be DER encoded */ private byte[] restoreTokenHeader(byte[] token) throws ASN1Exception { final DEREncoder encoder = new DEREncoder(); encoder.encodeImplicit(APPLICATION_SPECIFIC_MASK, 0); encoder.startSequence(); try { encoder.writeEncoded(mechanism.getDER()); } catch (GSSException e) { throw new ASN1Exception(e); } encoder.writeEncoded(token); encoder.endSequence(); return 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(); }