create method

create(certBytes, password) {#number[]_unknown}

Creates CertificateHolder object using byte array of PKCS12 store and its password.

create(certBytes: number[], password)
ParameterTypeDescription
certBytesnumber[]A byte array that contains data from an X.509 certificate.
passwordThe password required to access the X.509 certificate data.

Returns

An instance of CertificateHolder

Exceptions

exceptioncondition
RuntimeError (Proxy error(InvalidParameterException))Thrown if certBytes isnull
RuntimeError (Proxy error(InvalidParameterException))Thrown if password isnull
RuntimeError (Proxy error(SecurityException))Thrown if PKCS12 store contains no aliases
RuntimeError (Proxy error(IOException))Thrown if there is wrong password or corrupted file.

create(certBytes, password) {#number[]_string}

Creates CertificateHolder object using byte array of PKCS12 store and its password.

create(certBytes: number[], password: string)
ParameterTypeDescription
certBytesnumber[]A byte array that contains data from an X.509 certificate.
passwordstringThe password required to access the X.509 certificate data.

Returns

An instance of CertificateHolder

Exceptions

exceptioncondition
RuntimeError (Proxy error(InvalidParameterException))Thrown if certBytes isnull
RuntimeError (Proxy error(InvalidParameterException))Thrown if password isnull
RuntimeError (Proxy error(SecurityException))Thrown if PKCS12 store contains no aliases
RuntimeError (Proxy error(IOException))Thrown if there is wrong password or corrupted file.

create(fileName, password)

Creates CertificateHolder object using path to PKCS12 store and its password.

create(fileName: string, password: string)
ParameterTypeDescription
fileNamestringThe name of a certificate file.
passwordstringThe password required to access the X.509 certificate data.

Returns

An instance of CertificateHolder

Exceptions

exceptioncondition
RuntimeError (Proxy error(InvalidParameterException))Thrown if fileName isnull
RuntimeError (Proxy error(InvalidParameterException))Thrown if password isnull
RuntimeError (Proxy error(SecurityException))Thrown if PKCS12 store contains no aliases
RuntimeError (Proxy error(IOException))Thrown if there is wrong password or corrupted file.

create(fileName, password, alias)

Creates CertificateHolder object using path to PKCS12 store, its password and the alias by using which private key and certificate will be found.

create(fileName: string, password: string, alias: string)
ParameterTypeDescription
fileNamestringThe name of a certificate file.
passwordstringThe password required to access the X.509 certificate data.
aliasstringThe associated alias for a certificate and its private key

Returns

An instance of CertificateHolder

Exceptions

exceptioncondition
RuntimeError (Proxy error(InvalidParameterException))Thrown if fileName isnull
RuntimeError (Proxy error(InvalidParameterException))Thrown if password isnull
RuntimeError (Proxy error(SecurityException))Thrown if PKCS12 store contains no aliases
RuntimeError (Proxy error(IOException))Thrown if there is wrong password or corrupted file.
RuntimeError (Proxy error(SecurityException))Thrown if there is no private key with the given alias

Examples

Shows how to digitally sign documents.

// Create an X.509 certificate from a PKCS#12 store, which should contain a private key.
let certificateHolder = aw.DigitalSignatures.CertificateHolder.create(base.myDir + "morzal.pfx", "aw");

// Create a comment and date which will be applied with our new digital signature.
let signOptions = new aw.DigitalSignatures.SignOptions
{
  Comments = "My comment",
  SignTime = Date.now()
};

// Take an unsigned document from the local file system via a file stream,
// then create a signed copy of it determined by the filename of the output file stream.
using (Stream streamIn = new FileStream(base.myDir + "Document.docx", FileMode.open))
{
  using (Stream streamOut = new FileStream(base.artifactsDir + "DigitalSignatureUtil.SignDocument.docx", FileMode.OpenOrCreate))
  {
    aw.DigitalSignatures.DigitalSignatureUtil.sign(streamIn, streamOut, certificateHolder, signOptions);
  }
}

See Also