/** * Encodes the signature as a DER sequence (ASN.1 format). */ private byte[] asnEncode(byte[] sigBlob) throws IOException { byte[] r = new BigInteger(1, Arrays.copyOfRange(sigBlob, 0, 20)).toByteArray(); byte[] s = new BigInteger(1, Arrays.copyOfRange(sigBlob, 20, 40)).toByteArray(); ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new ASN1Integer(r)); vector.add(new ASN1Integer(s)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ASN1OutputStream asnOS = new ASN1OutputStream(baos); asnOS.writeObject(new DERSequence(vector)); asnOS.flush(); return baos.toByteArray(); } }
private static byte[] encodeWithoutSeqHeader(RDN[] rdns) throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream aOut = new ASN1OutputStream(bOut); for (RDN rdn: rdns) { aOut.writeObject(rdn); } aOut.close(); return bOut.toByteArray(); } }
/** * Return the default BER or DER encoding for this object. * * @return BER/DER byte encoded object. * @throws java.io.IOException on encoding error. */ public byte[] getEncoded() throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream aOut = new ASN1OutputStream(bOut); aOut.writeObject(this); return bOut.toByteArray(); }
out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo); out.writeLength(primitive.encodedLength()); out.writeObject(primitive); out.writeTag(flags, tagNo); out.writeImplicitObject(primitive); out.writeEncoded(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo, ZERO_BYTES);
void encode( ASN1OutputStream out) throws IOException { ASN1OutputStream dOut = out.getDERSubStream(); int length = getBodyLength(); out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED); out.writeLength(length); for (Enumeration e = this.getObjects(); e.hasMoreElements();) { Object obj = e.nextElement(); dOut.writeObject((ASN1Encodable)obj); } } }
/** * A note on the implementation: * <p> * As DL requires the constructed, definite-length model to * be used for structured types, this varies slightly from the * ASN.1 descriptions given. Rather than just outputting SET, * we also have to specify CONSTRUCTED, and the objects length. */ void encode( ASN1OutputStream out) throws IOException { ASN1OutputStream dOut = out.getDLSubStream(); int length = getBodyLength(); out.write(BERTags.SET | BERTags.CONSTRUCTED); out.writeLength(length); for (Enumeration e = this.getObjects(); e.hasMoreElements();) { Object obj = e.nextElement(); dOut.writeObject((ASN1Encodable)obj); } } }
void encode( ASN1OutputStream out) throws IOException { out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED); out.write(0x80); Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject((ASN1Encodable)e.nextElement()); } out.write(0x00); out.write(0x00); } }
throws IOException out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo); out.write(0x80); out.writeObject((ASN1Encodable)e.nextElement()); out.writeObject(obj); out.write(0x00); out.write(0x00);
/** * Gets the bytes for the PKCS#1 object. * @return a byte array */ public byte[] getEncodedPKCS1() { try { if (externalDigest != null) digest = externalDigest; else digest = sig.sign(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream dout = new ASN1OutputStream(bOut); dout.writeObject(new DEROctetString(digest)); dout.close(); return bOut.toByteArray(); } catch (Exception e) { throw new ExceptionConverter(e); } }
/** * Return the default BER or DER encoding for this object. * * @return BER/DER byte encoded object. * @throws java.io.IOException on encoding error. */ public byte[] getEncoded() throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream aOut = new ASN1OutputStream(bOut); aOut.writeObject(this); return bOut.toByteArray(); }
out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo); out.writeLength(primitive.encodedLength()); out.writeObject(primitive); out.writeTag(flags, tagNo); out.writeImplicitObject(primitive); out.writeEncoded(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo, ZERO_BYTES);
void encode( ASN1OutputStream out) throws IOException { ASN1OutputStream dOut = out.getDERSubStream(); int length = getBodyLength(); out.write(BERTags.SET | BERTags.CONSTRUCTED); out.writeLength(length); for (Enumeration e = this.getObjects(); e.hasMoreElements();) { Object obj = e.nextElement(); dOut.writeObject((ASN1Encodable)obj); } } }
/** * A note on the implementation: * <p> * As DL requires the constructed, definite-length model to * be used for structured types, this varies slightly from the * ASN.1 descriptions given. Rather than just outputting SEQUENCE, * we also have to specify CONSTRUCTED, and the objects length. */ void encode( ASN1OutputStream out) throws IOException { ASN1OutputStream dOut = out.getDLSubStream(); int length = getBodyLength(); out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED); out.writeLength(length); for (Enumeration e = this.getObjects(); e.hasMoreElements();) { Object obj = e.nextElement(); dOut.writeObject((ASN1Encodable)obj); } } }
void encode( ASN1OutputStream out) throws IOException { out.write(BERTags.SET | BERTags.CONSTRUCTED); out.write(0x80); Enumeration e = getObjects(); while (e.hasMoreElements()) { out.writeObject((ASN1Encodable)e.nextElement()); } out.write(0x00); out.write(0x00); } }
throws IOException out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo); out.write(0x80); out.writeObject((ASN1Encodable)e.nextElement()); out.writeObject(obj); out.write(0x00); out.write(0x00);
/** * Gets the bytes for the PKCS#1 object. * * @return a byte array */ public byte[] getEncodedPKCS1() { try { if (externalDigest != null) digest = externalDigest; else digest = sig.sign(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream dout = new ASN1OutputStream(bOut); dout.writeObject(new DEROctetString(digest)); dout.close(); return bOut.toByteArray(); } catch (Exception e) { throw new PdfException(e); } }
public X500Principal getIssuerX500Principal() { try { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ASN1OutputStream aOut = new ASN1OutputStream(bOut); aOut.writeObject(c.getIssuer()); return new X500Principal(bOut.toByteArray()); } catch (IOException e) { throw new IllegalStateException("can't encode issuer DN"); } }
/** * Encodes the signature as a DER sequence (ASN.1 format). */ private byte[] asnEncode(byte[] sigBlob) throws IOException { Buffer.PlainBuffer sigbuf = new Buffer.PlainBuffer(sigBlob); byte[] r = sigbuf.readBytes(); byte[] s = sigbuf.readBytes(); ASN1EncodableVector vector = new ASN1EncodableVector(); vector.add(new ASN1Integer(r)); vector.add(new ASN1Integer(s)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ASN1OutputStream asnOS = new ASN1OutputStream(baos); asnOS.writeObject(new DERSequence(vector)); asnOS.flush(); return baos.toByteArray(); } }
out.writeTag(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo); out.writeLength(primitive.encodedLength()); out.writeObject(primitive); out.writeTag(flags, tagNo); out.writeImplicitObject(primitive); out.writeEncoded(BERTags.CONSTRUCTED | BERTags.TAGGED, tagNo, ZERO_BYTES);
void encode( ASN1OutputStream out) throws IOException { ASN1OutputStream dOut = out.getDERSubStream(); int length = getBodyLength(); out.write(BERTags.SEQUENCE | BERTags.CONSTRUCTED); out.writeLength(length); for (Enumeration e = this.getObjects(); e.hasMoreElements();) { Object obj = e.nextElement(); dOut.writeObject((ASN1Encodable)obj); } } }