Package com.itextpdf.signatures
Class PrivateKeySignature
java.lang.Object
com.itextpdf.signatures.PrivateKeySignature
- All Implemented Interfaces:
-
IExternalSignature
Implementation of the
IExternalSignature
interface that can be used when you have a PrivateKey
object.
-
Constructor Summary
ConstructorDescriptionPrivateKeySignature
(PrivateKey pk, String hashAlgorithm, String provider) Creates aPrivateKeySignature
instance.PrivateKeySignature
(PrivateKey pk, String hashAlgorithm, String signatureAlgorithm, String provider, IApplicableSignatureParams params) Creates aPrivateKeySignature
instance. -
Method Summary
Modifier and TypeMethodDescriptionReturns the digest algorithm.Returns the signature algorithm used for signing, disregarding the digest function.Return the algorithm parameters that need to be encoded together with the signature mechanism identifier.byte[]
sign
(byte[] message) Signs the given message using the encryption algorithm in combination with the hash algorithm.
-
Constructor Details
-
PrivateKeySignature
Creates aPrivateKeySignature
instance.- Parameters:
-
pk
- APrivateKey
object. -
hashAlgorithm
- A hash algorithm (e.g. "SHA-1", "SHA-256",...). -
provider
- A security provider (e.g. "BC").
-
PrivateKeySignature
public PrivateKeySignature(PrivateKey pk, String hashAlgorithm, String signatureAlgorithm, String provider, IApplicableSignatureParams params) Creates aPrivateKeySignature
instance.- Parameters:
-
pk
- APrivateKey
object. -
hashAlgorithm
- A hash algorithm (e.g. "SHA-1", "SHA-256",...). -
signatureAlgorithm
- A signiture algorithm (e.g. "RSASSA-PSS", "id-signedData", "sha256WithRSAEncryption", ...) -
provider
- A security provider (e.g. "BC"). -
params
- Parameters for using RSASSA-PSS or other algorithms requiring them.
-
-
Method Details
-
getDigestAlgorithmName
Returns the digest algorithm.- Specified by:
-
getDigestAlgorithmName
in interfaceIExternalSignature
- Returns:
- The digest algorithm (e.g. "SHA-1", "SHA-256,...").
-
getSignatureAlgorithmName
Returns the signature algorithm used for signing, disregarding the digest function.- Specified by:
-
getSignatureAlgorithmName
in interfaceIExternalSignature
- Returns:
- The signature algorithm ("RSA", "DSA", "ECDSA", "Ed25519" or "Ed448").
-
getSignatureMechanismParameters
Return the algorithm parameters that need to be encoded together with the signature mechanism identifier. If there are no parameters, return `null`. A non-null value is required for RSASSA-PSS; seeRSASSAPSSMechanismParams
.- Specified by:
-
getSignatureMechanismParameters
in interfaceIExternalSignature
- Returns:
- algorithm parameters
-
sign
Signs the given message using the encryption algorithm in combination with the hash algorithm.- Specified by:
-
sign
in interfaceIExternalSignature
- Parameters:
-
message
- The message you want to be hashed and signed. - Returns:
- A signed message digest.
- Throws:
-
GeneralSecurityException
- when requested cryptographic algorithm or security provider is not available
-