Package com.itextpdf.signatures
Class PrivateKeySignature
- java.lang.Object
-
- com.itextpdf.signatures.PrivateKeySignature
-
- All Implemented Interfaces:
IExternalSignature
public class PrivateKeySignature extends java.lang.Object implements IExternalSignature
Implementation of theIExternalSignatureinterface that can be used when you have aPrivateKeyobject.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringhashAlgorithmThe hash algorithm.private IApplicableSignatureParamsparametersThe algorithm parameters.private java.security.PrivateKeypkThe private key object.private java.lang.StringproviderThe security providerprivate java.lang.StringsignatureAlgorithmThe encryption algorithm (obtained from the private key)
-
Constructor Summary
Constructors Constructor Description PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String provider)Creates aPrivateKeySignatureinstance.PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String signatureAlgorithm, java.lang.String provider, IApplicableSignatureParams params)Creates aPrivateKeySignatureinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetDigestAlgorithmName()Returns the digest algorithm.java.lang.StringgetSignatureAlgorithmName()Returns the signature algorithm used for signing, disregarding the digest function.private java.lang.StringgetSignatureMechanismName()ISignatureMechanismParamsgetSignatureMechanismParameters()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.
-
-
-
Field Detail
-
pk
private final java.security.PrivateKey pk
The private key object.
-
hashAlgorithm
private final java.lang.String hashAlgorithm
The hash algorithm.
-
signatureAlgorithm
private final java.lang.String signatureAlgorithm
The encryption algorithm (obtained from the private key)
-
provider
private final java.lang.String provider
The security provider
-
parameters
private final IApplicableSignatureParams parameters
The algorithm parameters.
-
-
Constructor Detail
-
PrivateKeySignature
public PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String provider)Creates aPrivateKeySignatureinstance.- Parameters:
pk- APrivateKeyobject.hashAlgorithm- A hash algorithm (e.g. "SHA-1", "SHA-256",...).provider- A security provider (e.g. "BC").
-
PrivateKeySignature
public PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String signatureAlgorithm, java.lang.String provider, IApplicableSignatureParams params)Creates aPrivateKeySignatureinstance.- Parameters:
pk- APrivateKeyobject.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 Detail
-
getDigestAlgorithmName
public java.lang.String getDigestAlgorithmName()
Returns the digest algorithm.- Specified by:
getDigestAlgorithmNamein interfaceIExternalSignature- Returns:
- The digest algorithm (e.g. "SHA-1", "SHA-256,...").
-
getSignatureAlgorithmName
public java.lang.String getSignatureAlgorithmName()
Returns the signature algorithm used for signing, disregarding the digest function.- Specified by:
getSignatureAlgorithmNamein interfaceIExternalSignature- Returns:
- The signature algorithm ("RSA", "DSA", "ECDSA", "Ed25519" or "Ed448").
-
getSignatureMechanismParameters
public ISignatureMechanismParams 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:
getSignatureMechanismParametersin interfaceIExternalSignature- Returns:
- algorithm parameters
-
sign
public byte[] sign(byte[] message) throws java.security.GeneralSecurityExceptionSigns the given message using the encryption algorithm in combination with the hash algorithm.- Specified by:
signin interfaceIExternalSignature- Parameters:
message- The message you want to be hashed and signed.- Returns:
- A signed message digest.
- Throws:
java.security.GeneralSecurityException- when requested cryptographic algorithm or security provider is not available
-
getSignatureMechanismName
private java.lang.String getSignatureMechanismName()
-
-