Package com.itextpdf.text.pdf.security
Class PrivateKeySignature
- java.lang.Object
-
- com.itextpdf.text.pdf.security.PrivateKeySignature
-
- All Implemented Interfaces:
ExternalSignature
public class PrivateKeySignature extends java.lang.Object implements ExternalSignature
Implementation of the ExternalSignature interface that can be used when you have a PrivateKey object.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
encryptionAlgorithm
The encryption algorithm (obtained from the private key)private java.lang.String
hashAlgorithm
The hash algorithm.private java.security.PrivateKey
pk
The private key object.private java.lang.String
provider
The security provider
-
Constructor Summary
Constructors Constructor Description PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String provider)
Creates an ExternalSignature instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getEncryptionAlgorithm()
Returns the encryption algorithm used for signing.java.lang.String
getHashAlgorithm()
Returns the hash algorithm.byte[]
sign(byte[] b)
Signs it using the encryption algorithm in combination with the digest algorithm.
-
-
-
Field Detail
-
pk
private java.security.PrivateKey pk
The private key object.
-
hashAlgorithm
private java.lang.String hashAlgorithm
The hash algorithm.
-
encryptionAlgorithm
private java.lang.String encryptionAlgorithm
The encryption algorithm (obtained from the private key)
-
provider
private java.lang.String provider
The security provider
-
-
Constructor Detail
-
PrivateKeySignature
public PrivateKeySignature(java.security.PrivateKey pk, java.lang.String hashAlgorithm, java.lang.String provider)
Creates an ExternalSignature instance- Parameters:
pk
- a PrivateKey objecthashAlgorithm
- the hash algorithm (e.g. "SHA-1", "SHA-256",...)provider
- the security provider (e.g. "BC")
-
-
Method Detail
-
getHashAlgorithm
public java.lang.String getHashAlgorithm()
Returns the hash algorithm.- Specified by:
getHashAlgorithm
in interfaceExternalSignature
- Returns:
- the hash algorithm (e.g. "SHA-1", "SHA-256,...")
- See Also:
ExternalSignature.getHashAlgorithm()
-
getEncryptionAlgorithm
public java.lang.String getEncryptionAlgorithm()
Returns the encryption algorithm used for signing.- Specified by:
getEncryptionAlgorithm
in interfaceExternalSignature
- Returns:
- the encryption algorithm ("RSA" or "DSA")
- See Also:
ExternalSignature.getEncryptionAlgorithm()
-
sign
public byte[] sign(byte[] b) throws java.security.GeneralSecurityException
Signs it using the encryption algorithm in combination with the digest algorithm.- Specified by:
sign
in interfaceExternalSignature
- Parameters:
message
- the message you want to be hashed and signed- Returns:
- a signed message digest
- Throws:
java.security.GeneralSecurityException
-
-