Cryptographic operations

The methods described below are provided to perform cryptographic operations. Note that only operations with the private keys are available (which requires access to the hardware). Operations using the public keys can be made using pure-JavaScript libraries provided by third-parties.

Key.sign(hash[, algorithm])

Signs the provided hash using a private key. The operation will use PKCS#1 padding.

The algorithm of the hash needs to be indicated if the OID needs to be added within the signature block. The hashAlg parameter can take the following values:

  • null or undefined: The hash data will be signed as provided. Not available for qualified signature keys.

  • "sha1", "sha256", "sha384" or "sha512": The corresponding OID will be prepended. Not available for qualified signature keys.

  • "sha1-partial" or "sha256-partial": The hash must be provided as a partial hash block (containing intermediate hash values) as defined by the IAS specifications. The hash will be finalized by the card and the corresponding OID will be prepended. Available only for qualified signature keys.

The Key.partialHash property can be used to check whether the key is a qualified signature key that requires partial hashing.

Arguments
  • hashArrayBuffer, Buffer or Uint8Array containing the hash value.

  • hashAlg – (optional) Algorithm of the hash.

Returns

A Promise resolving to an ArrayBuffer containing the signature.

Key.hashAndSign(data, hashAlg)

Hashes the provided data and signs the hash using a private key. The operation will use PKCS#1 padding.

The hashAlg parameter indicates the hash algorithm to use and can take the following values:

  • "sha1" or "sha256": Available for all keys (SHA-1 may be forbidden with qualified signature keys depending on the card profile). The API will automatically take care of the partial hashing requirement when used with a qualified signature key.

  • "sha384" or "sha512": Not available for qualified signature keys.

Arguments
  • data – Data to hash, provided as a string or as a Blob object.

  • hashAlg – Algorithm of the hash.

Returns

A Promise resolving to an ArrayBuffer containing the signature.

Key.decrypt(data)

Decrypts the provided data using a private key. The operation will use PKCS#1 padding.

Arguments
  • dataArrayBuffer, Buffer or Uint8Array containing the ciphertext data to decrypt.

Returns

A Promise resolving to an ArrayBuffer containing the plaintext data.