public byte[] getValue() { DEREncoder encoder = new DEREncoder(); encodeTo(encoder); return encoder.getEncoded(); } }
/** * Implementation of the {@code engineInit} method. * * @param paramSpec the parameter specification * @throws InvalidParameterSpecException if an argument is invalid or encoding failed */ protected final void engineInit(final AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { final Class<P> parameterType = getParameterType(); if (parameterType.isInstance(paramSpec)) try { DEREncoder encoder = new DEREncoder(); final P cast = parameterType.cast(paramSpec); engineEncode(encoder, cast); encoded = encoder.getEncoded(); this.parameterSpec = cast; } catch (ASN1Exception e) { throw log.failedToEncode(e); } else { throw log.invalidParameterSpec(parameterType, paramSpec.getClass()); } }
@Override public void encodeBitString(BigInteger integer) { ByteStringBuilder target = new ByteStringBuilder(); new DEREncoder(target).encodeInteger(integer); encodeBitString(target.toArray()); }
/** * Build the principal. On return (with any outcome), this builder is re-set for building a new principal. * * @return the constructed principal (not {@code null}) * @throws IllegalArgumentException if the principal is somehow invalid */ public X500Principal build() throws IllegalArgumentException { final DEREncoder derEncoder = new DEREncoder(); derEncoder.startSequence(); for (Collection<X500AttributeTypeAndValue> itemSet : items) { derEncoder.startSet(); for (X500AttributeTypeAndValue item : itemSet) { item.encodeTo(derEncoder); } derEncoder.endSet(); } derEncoder.endSequence(); return new X500Principal(derEncoder.getEncoded()); } }
DEREncoder tbsEncoder = new DEREncoder(); encodeCertificationRequestInfo(tbsEncoder);
byte[] tbsCertificate = getTBSBytes(); DEREncoder derEncoder = new DEREncoder();
/** * <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; } }
addExtension(subjectKeyIdentifierExtension); DEREncoder encoder = new DEREncoder(); encodeCertificationRequest(encoder); return new PKCS10CertificateSigningRequest(this, 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(); }
/** * 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(); }
/** * 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 derEncoder = new DEREncoder(); derEncoder.encodeObjectIdentifier(extension.getId()); if (extension.isCritical()) derEncoder.encodeBoolean(true); final DEREncoder subEncoder = new DEREncoder(); extension.encodeTo(subEncoder); derEncoder.encodeOctetString(subEncoder.getEncoded());
final X509EncodedKeySpec publicSpec = keyFactory.getKeySpec(keyFactory.translateKey(publicKey), X509EncodedKeySpec.class); final PKCS8EncodedKeySpec privateSpec = keyFactory.getKeySpec(keyFactory.translateKey(privateKey), PKCS8EncodedKeySpec.class); final DEREncoder encoder = new DEREncoder(); encoder.startSequence(); encoder.writeEncoded(publicSpec.getEncoded()); } else if (credentialClass == X509CertificateChainPublicCredential.class) { final X509Certificate[] x509Certificates = credential.castAndApply(X509CertificateChainPublicCredential.class, X509CertificateChainPublicCredential::getCertificateChain); final DEREncoder encoder = new DEREncoder(); encoder.encodeInteger(x509Certificates.length); encoder.startSequence(); final Password password = credential.castAndApply(PasswordCredential.class, PasswordCredential::getPassword); final String algorithm = password.getAlgorithm(); final DEREncoder encoder = new DEREncoder(); final PasswordFactory passwordFactory = PasswordFactory.getInstance(algorithm); switch (algorithm) {
final DEREncoder encoder = new DEREncoder(); try { encoder.startSequence(); decoder.endSequence(); final DEREncoder tbsEncoder = new DEREncoder(); tbsEncoder.startSequence(); tbsEncoder.encodeOctetString(randomA); final DEREncoder encoder = new DEREncoder(); try { encoder.startSequence(); final DEREncoder tbsEncoder = new DEREncoder(); tbsEncoder.startSequence(); tbsEncoder.encodeOctetString(randomB);
final DEREncoder encoder = new DEREncoder(); try { encoder.startSequence(); final DEREncoder tbsEncoder = new DEREncoder(); tbsEncoder.startSequence(); tbsEncoder.encodeOctetString(randomA); decoder.endSequence(); final DEREncoder tbsEncoder = new DEREncoder(); tbsEncoder.startSequence(); tbsEncoder.encodeOctetString(randomB);
public byte[] getValue() { DEREncoder encoder = new DEREncoder(); encodeTo(encoder); return encoder.getEncoded(); } }
public byte[] getValue() { DEREncoder encoder = new DEREncoder(); encodeTo(encoder); return encoder.getEncoded(); } }
public byte[] getValue() { DEREncoder encoder = new DEREncoder(); encodeTo(encoder); return encoder.getEncoded(); } }
@Override public void encodeBitString(BigInteger integer) { ByteStringBuilder target = new ByteStringBuilder(); new DEREncoder(target).encodeInteger(integer); encodeBitString(target.toArray()); }