public abstract class AbstractSignature extends java.lang.Object implements Signature
Signature
implementationModifier and Type | Field and Description |
---|---|
private java.lang.String |
algorithm |
private java.security.Signature |
signatureInstance |
Modifier | Constructor and Description |
---|---|
protected |
AbstractSignature(java.lang.String algorithm) |
Modifier and Type | Method and Description |
---|---|
protected java.security.Signature |
doInitSignature(SessionContext session,
java.lang.String algo,
java.security.Key key,
boolean forSigning)
Initializes the internal signature instance
|
protected boolean |
doVerify(byte[] data) |
protected java.util.Map.Entry<java.lang.String,byte[]> |
extractEncodedSignature(byte[] sig,
java.util.Collection<java.lang.String> expectedTypes)
Makes an attempt to detect if the signature is encoded or pure data
|
protected java.util.Map.Entry<java.lang.String,byte[]> |
extractEncodedSignature(byte[] sig,
java.util.function.Predicate<? super java.lang.String> typeSelector) |
java.lang.String |
getAlgorithm() |
protected java.security.Signature |
getSignature() |
void |
initSigner(SessionContext session,
java.security.PrivateKey key) |
void |
initVerifier(SessionContext session,
java.security.PublicKey key) |
byte[] |
sign(SessionContext session)
Compute the signature
|
java.lang.String |
toString() |
void |
update(SessionContext session,
byte[] hash,
int off,
int len)
Update the computed signature with the given data
|
private java.security.Signature signatureInstance
private final java.lang.String algorithm
public final java.lang.String getAlgorithm()
getAlgorithm
in interface AlgorithmNameProvider
protected java.security.Signature doInitSignature(SessionContext session, java.lang.String algo, java.security.Key key, boolean forSigning) throws java.security.GeneralSecurityException
session
- The SessionContext
for calling this method - may be null
if not
called within a session contextalgo
- The signature's algorithm namekey
- the Key
that is provided for initialization - a PrivateKey
for
signing and a PublicKey
for verificationforSigning
- If true
then it is being initialized for signing, otherwise for
verifying a signatureSignature
instancejava.security.GeneralSecurityException
- if failed to initializeprotected java.security.Signature getSignature()
Signature
instance - null
if not initializeddoInitSignature(SessionContext, String, Key, boolean)
public byte[] sign(SessionContext session) throws java.lang.Exception
Signature
sign
in interface Signature
session
- The SessionContext
for calling this method - may be null
if not called within a
session contextjava.lang.Exception
- If failed to calculate the signaturepublic void initVerifier(SessionContext session, java.security.PublicKey key) throws java.lang.Exception
initVerifier
in interface Signature
session
- The SessionContext
for calling this method - may be null
if not called within a
session contextkey
- The PublicKey
to be used for verifying signaturesjava.lang.Exception
- If failed to initializepublic void initSigner(SessionContext session, java.security.PrivateKey key) throws java.lang.Exception
initSigner
in interface Signature
session
- The SessionContext
for calling this method - may be null
if not called within a
session contextkey
- The PrivateKey
to be used for signingjava.lang.Exception
- If failed to initializepublic void update(SessionContext session, byte[] hash, int off, int len) throws java.lang.Exception
Signature
update
in interface Signature
session
- The SessionContext
for calling this method - may be null
if not called within a
session contexthash
- The hash data bufferoff
- Offset of hash data in bufferlen
- Length of hash datajava.lang.Exception
- If failed to updateprotected java.util.Map.Entry<java.lang.String,byte[]> extractEncodedSignature(byte[] sig, java.util.Collection<java.lang.String> expectedTypes)
sig
- The original signatureexpectedTypes
- The expected encoded key typesAbstractMap.SimpleImmutableEntry
where first value is the key type and second value is the
data - null
if not encodedprotected java.util.Map.Entry<java.lang.String,byte[]> extractEncodedSignature(byte[] sig, java.util.function.Predicate<? super java.lang.String> typeSelector)
protected boolean doVerify(byte[] data) throws java.security.SignatureException
java.security.SignatureException
public java.lang.String toString()
toString
in class java.lang.Object