@Override protected void generateContent() { content = encodeBytes(getValueBytes()); }
@Override protected void checkPdfString(PdfString string) { if (string.getValueBytes().length > getMaxStringLength()) { throw new PdfAConformanceException(PdfAConformanceException.PDF_STRING_IS_TOO_LONG); } }
@Override protected void checkPdfString(PdfString string) { if (string.getValueBytes().length > getMaxStringLength()) { throw new PdfAConformanceException(PdfAConformanceException.PDF_STRING_IS_TOO_LONG); } }
if (str.isHexWriting()) { sb.append("<"); byte b[] = str.getValueBytes(); int len = b.length; String hex;
@Override public void add(PdfObject pdfObject) { if (pdfObject.isNumber()) { add(((PdfNumber)pdfObject).floatValue()); } else if (pdfObject instanceof PdfString) { add(((PdfString)pdfObject).getValueBytes()); } }
protected static byte[] computeGlobalKeyOnReading(PdfDictionary encryptionDictionary, PrivateKey certificateKey, Certificate certificate, String certificateKeyProvider, IExternalDecryptionProcess externalDecryptionProcess, boolean encryptMetadata, String digestAlgorithm) { PdfArray recipients = encryptionDictionary.getAsArray(PdfName.Recipients); if (recipients == null) { recipients = encryptionDictionary.getAsDictionary(PdfName.CF) .getAsDictionary(PdfName.DefaultCryptFilter) .getAsArray(PdfName.Recipients); } byte[] envelopedData = EncryptionUtils.fetchEnvelopedData(certificateKey, certificate, certificateKeyProvider, externalDecryptionProcess, recipients); byte[] encryptionKey; MessageDigest md; try { md = MessageDigest.getInstance(digestAlgorithm); md.update(envelopedData, 0, 20); for (int i = 0; i < recipients.size(); i++) { byte[] encodedRecipient = recipients.getAsString(i).getValueBytes(); md.update(encodedRecipient); } if (!encryptMetadata) { md.update(new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255}); } encryptionKey = md.digest(); } catch (Exception f) { throw new PdfException(PdfException.PdfDecryption, f); } return encryptionKey; }
/** * Encrypt content of {@code value} and set as content. {@code generateContent()} won't be called. * * @param encrypt @see PdfEncryption * @return true if value was encrypted, otherwise false. */ protected boolean encrypt(PdfEncryption encrypt) { if (checkState(PdfObject.UNENCRYPTED)) { return false; } if (encrypt != decryption) { if (decryption != null) { generateValue(); } if (encrypt != null && !encrypt.isEmbeddedFilesOnly()) { byte[] b = encrypt.encryptByteArray(getValueBytes()); content = encodeBytes(b); return true; } } return false; }
/** * {@inheritDoc} */ @Override public GlyphLine decodeIntoGlyphLine(PdfString content) { byte[] contentBytes = content.getValueBytes(); List<Glyph> glyphs = new ArrayList<>(contentBytes.length); for (byte b : contentBytes) { int code = b & 0xff; Glyph glyph = null; if (toUnicode != null && toUnicode.lookup(code) != null && (glyph = fontProgram.getGlyphByCode(code)) != null) { if (!Arrays.equals(toUnicode.lookup(code), glyph.getChars())) { // Copy the glyph because the original one may be reused (e.g. standard Helvetica font program) glyph = new Glyph(glyph); glyph.setChars(toUnicode.lookup(code)); } } else { int uni = fontEncoding.getUnicode(code); if (uni > -1) { glyph = getGlyph(uni); } else if (fontEncoding.getBaseEncoding() == null) { glyph = fontProgram.getGlyphByCode(code); } } if (glyph != null) { glyphs.add(glyph); } } return new GlyphLine(glyphs); }
CMSEnvelopedData data; try { data = new CMSEnvelopedData(recipient.getValueBytes()); Iterator<RecipientInformation> recipientCertificatesIt = data.getRecipientInfos().getRecipients().iterator(); while (recipientCertificatesIt.hasNext()) { CMSEnvelopedData data; try { data = new CMSEnvelopedData(recipient.getValueBytes()); RecipientInformation recipientInfo = data.getRecipientInfos().get(externalDecryptionProcess.getCmsRecipientId()); if (recipientInfo != null) {
/** * Shows text (operator TJ) * * @param textArray the text array. Each element of array can be a string or a number. * If the element is a string, this operator shows the string. * If it is a number, the operator adjusts the text position by that amount. * The number is expressed in thousandths of a unit of text space. * This amount is subtracted from the current horizontal or vertical coordinate, depending on the writing mode. * @return current canvas. */ public PdfCanvas showText(PdfArray textArray) { if (currentGs.getFont() == null) throw new PdfException(PdfException.FontAndSizeMustBeSetBeforeWritingAnyText, currentGs); contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("[")); for (PdfObject obj : textArray) { if (obj.isString()) { StreamUtil.writeEscapedString(contentStream.getOutputStream(), ((PdfString) obj).getValueBytes()); } else if (obj.isNumber()) { contentStream.getOutputStream().writeFloat(((PdfNumber) obj).floatValue()); } } contentStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("]")); contentStream.getOutputStream().writeBytes(TJ); return this; }
PdfObject id2 = ca.get(3); if (id2 instanceof PdfString) { palette = ((PdfString) id2).getValueBytes(); } else if (id2 instanceof PdfStream) { palette = (((PdfStream) id2)).getBytes();
if (cert == null) cert = signature.getPdfObject().getAsArray(PdfName.Cert).getAsString(0); pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), cert.getValueBytes(), provider); } else pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), sub, provider);
if (cert == null) cert = signature.getPdfObject().getAsArray(PdfName.Cert).getAsString(0); pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), cert.getValueBytes(), provider); } else pk = new PdfPKCS7(PdfEncodings.convertToBytes(contents.getValue(), null), sub, provider);