Skip to content
zboris12 edited this page Nov 21, 2022 · 7 revisions

Enum Definitions

Crypto.Mode

🥚🥚🥚

  • Type: number
Name Value Description
RC4_40 0 40bit RC4 Encryption
RC4_128 1 128bit RC4 Encryption
AES_128 2 128bit AES Encryption
AES_256 3 256bit AES Encryption

Type Definitions

DSSInfo

🌮🌮🌮

Name Type Attributes Description
certs Array<forge_cert> optional An array of necessary certificates.
ocsps Array<Uint8Array> optional An array of OCSPs' response.
crls Array<Uint8Array> optional The array of CRLs.

EncryptOption

🌮🌮🌮

Name Type Attributes Description
mode Crypto.Mode required The mode of encryption
permissions Array<string> optional The set of permissions to be blocked 1️⃣
userpwd string optional User password. Used when opening the pdf.
ownerpwd string optional Owner password. If not specified, a random value is used.
pubkeys Array<PubKeyInfo> optional An array of recipients containing public-key certificates ('c') and permissions ('p').

1️⃣ permissions can be the values listed blow.

  • copy: (Only valid on public-key mode) Copy text and graphics from the document;
  • print: Print the document;
  • modify: Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
  • copy-extract: Copy or otherwise extract text and graphics from the document;
  • annot-forms: Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
  • fill-forms: Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
  • extract: Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
  • assemble: Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
  • print-high: Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.

PubKeyInfo

🌮🌮🌮

Name Type Attributes Description
c Array<number>
🍴Uint8Array
🍴ArrayBuffer
🍴string
🍴forge_cert
optional A certificate.
p Array<string> optional An array of permissions you want to block. Valid values see EncryptOption

SignAreaInfo

🌮🌮🌮

Name Type Attributes Description
x number required Distance from left
y number required Distance from top
w number required Width
h number required Height

SignDrawInfo

🌮🌮🌮

Name Type Attributes Description
area SignAreaInfo required The signature's drawing area, these numbers are dots on 72dpi.
pageidx number optional The index of a page where the signature will be drawn. Default is 0.
imgData Array<number>
🍴Uint8Array
🍴ArrayBuffer
🍴string
optional The image's data.
imgType string optional The image's type, only support jpg and png
text string optional A text drawing for the signature, not implemented yet
fontData PDFLib.StandardFonts
🍴Array<number>
🍴Uint8Array
🍴ArrayBuffer
🍴string
optional The font's data for drawing text, not implemented yet

SignOption

🌮🌮🌮

Name Type Attributes Description
p12cert Array<number>
🍴Uint8Array
🍴ArrayBuffer
🍴string
optional Certificate's data. In the case of adding a document timestamp, it must be omitted.
pwd string optional The passphrase of the certificate. In the case of adding a document timestamp, it must be omitted.
permission number optional The modification permissions granted for this document. 1️⃣
reason string optional The reason for signing
location string optional Your location
contact string optional Your contact information
signdate TsaServiceInfo
🍴string
🍴Date
optional In the case of adding a document timestamp, it can't be omitted and can't be a Date. 2️⃣
signame string optional The name of the signature
drawinf SignDrawInfo optional Visible signature's information
ltv number optional The method of how to enable LTV 3️⃣
debug boolean optional To output debug informations or not

1️⃣ permission is a setting of DocMDP. Valid values are:

  • 1: No changes to the document are permitted; any change to the document invalidates the signature.
  • 2: Permitted changes are filling in forms, instantiating page templates, and signing; other changes invalidate the signature.
  • 3: Permitted changes are the same as for 2, as well as annotation creation, deletion, and modification; other changes invalidate the signature.

2️⃣ signdate

3️⃣ ltv's valid values are:

  • 1: auto; Try using OCSP only to enable the LTV first; If can't, try using CRL to enable the LTV.
  • 2: crl only; Only try using CRL to enable the LTV.

TsaServiceInfo

🌮🌮🌮

Name Type Attributes Description
url string required The url of TSA.
len number optional The length of signature's placeholder.
headers Object<string, *> optional The customized headers for sending to tsa server.

Function Definitions

u8arrToRaw

🫕🫕🫕

u8arrToRaw(uarr) ➡️ string

Converts an Uint8Array to a raw string.

Name Type Attributes Description
uarr Uint8Array required The target Uint8Array

rawToU8arr

🫕🫕🫕

rawToU8arr(raw) ➡️ Uint8Array

Converts a raw string to an Uint8Array.

Name Type Attributes Description
raw string required The target string

Classes

CertsChain

🥐🥐🥐

Constructor

new CertsChain(certsopt)

Name Type Attributes Description
certs Array<forge_cert>
🍴Array<forge.asn1>
🍴Array<string>
optional An array of certificates.

Methods

buildChain(cert) ➡️ Promise<boolean>

Build the certificates chain from the specified certificate, and returns true if this operation is successful.

Name Type Attributes Description
cert forge_cert required A certificate to start build by looking for it's issuer.

getAllCerts() ➡️ Array<forge_cert>

Returns an array of all certificates.

getSignCert() ➡️ forge_cert

Returns the certificate for signing.

isSelfSignedCert() ➡️ boolean

Returns true if the certificate for signing is a self-signed certificate.

prepareDSSInf(crlOnlyopt) ➡️ Promise<DSSInfo>

Returns the informations of DSS.

Name Type Attributes Description
crlOnly boolean optional Query CRL only or try query OCSP first.

PdfCryptor

🥐🥐🥐

Constructor

new PdfCryptor(encopt)

Name Type Attributes Description
encopt EncryptOption required Infomations of encryption.

Methods

encryptObject(num, val)

Encrypts the content of the specified pdf object.

Name Type Attributes Description
num number required The object number.
val PDFLib.PDFObject required The target object.

encryptPdf(pdf, refopt) ➡️ Promise<PDFLib.PDFDocument>

Encrypts the contents in the pdf and returns the pdf document.

Name Type Attributes Description
pdf PDFLib.PDFDocument
🍴Array<number>
🍴Uint8Array
🍴ArrayBuffer
🍴string
required The target pdf.
ref PDFLib.PDFRef optional The unique reference will be assigned to the encryption information.

PdfSigner

🥐🥐🥐

Constructor

new PdfSigner(signopt)

Name Type Attributes Description
signopt SignOption required Infomations of signing.

Methods

sign(pdf, cypoptopt) ➡️ Promise<Uint8Array>

Sign the pdf and returns the binary data.

Name Type Attributes Description
pdf PDFLib.PDFDocument Array<number> Uint8Array
cypopt EncryptOption optional The informations of encryption.

TsaFetcher

🥐🥐🥐

Constructor

new TsaFetcher(inf)

Name Type Attributes Description
inf TsaServiceInfo required Infomations of TSA.

Properties

Name Type Description
url string The url of TSA.
len number The length of signature which is generated by the TSA.

Methods

getCertsChain() ➡️ CertsChain

Get the certificates' chain from the response of TSA.

getToken(forP7opt) ➡️ forge.asn1

Get the token data in response from TSA.

Name Type Attributes Description
forP7 boolean optional To create an asn1 for appending to a pkcs#7 signature or not.

queryTsa(data) ➡️ Promise<string>

Query TSA to sign the data and returns error message if error occured.

Name Type Attributes Description
data string required The data needs to be signed.

Note

  1. CRL📢 Certificate Revocation List
  2. DDS📢 Document Security Store
  3. DocMDP📢 Document Modification Detection and Prevention
  4. LTV📢 Long-Term Validation
  5. OCSP📢 Online Certificate Status Protocol
  6. TSA📢 Time Stamp Authority
Clone this wiki locally