Top Description Fields Constructors Methods
org.apache.sshd.common.signature

public abstract Class AbstractSignature

extends Object
implements Signature
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.signature.Signature, org.apache.sshd.common.AlgorithmNameProvider
Known Direct Subclasses
org.apache.sshd.common.signature.SignatureDSA, org.apache.sshd.common.signature.SignatureECDSA, org.apache.sshd.common.signature.SignatureRSA, org.apache.sshd.common.util.security.eddsa.generic.GenericSignatureEd25519
Imports
java.nio.charset.StandardCharsets, java.security.GeneralSecurityException, .Key, .PrivateKey, .PublicKey, .SignatureException, java.util.AbstractMap.SimpleImmutableEntry, .Collection, .Map, .Objects, java.util.function.Predicate, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.util.GenericUtils, .NumberUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.BufferUtils, org.apache.sshd.common.util.security.SecurityUtils

Useful base class for Signature implementation
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private final String
private Signature

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected Signature

Returns:

The java.security.Signature instance
doInitSignature
(SessionContext
The SessionContext for calling this method - may be null if not called within a session context
session
,
String
The signature's algorithm name
algo
,
Key
the Key that is provided for initialization - a PrivateKey for signing and a PublicKey for verification
key
,
boolean
If true then it is being initialized for signing, otherwise for verifying a signature
forSigning
)

Initializes the internal signature instance

protected boolean
doVerify(byte[] data)

protected Map.Entry<String, byte[]>

Returns:

A SimpleImmutableEntry where first value is the key type and second value is the data - null if not encoded
extractEncodedSignature
(byte[]
The original signature
sig
,
Collection<String>
The expected encoded key types
expectedTypes
)

Makes an attempt to detect if the signature is encoded or pure data

protected Map.Entry<String, byte[]>
extractEncodedSignature(byte[] sig, Predicate<? super String> typeSelector)

public final String
protected Signature

Returns:

The current java.security.Signature instance - null if not initialized
getSignature
()

public void
initSigner(SessionContext
The SessionContext for calling this method - may be null if not called within a session context
session
,
PrivateKey
The PrivateKey to be used for signing
key
)

Implements org.apache.sshd.common.signature.Signature.initSigner.

public void
initVerifier(SessionContext
The SessionContext for calling this method - may be null if not called within a session context
session
,
PublicKey
The PublicKey to be used for verifying signatures
key
)

Implements org.apache.sshd.common.signature.Signature.initVerifier.

public byte[]
sign(SessionContext
The SessionContext for calling this method - may be null if not called within a session context
session
)

Implements org.apache.sshd.common.signature.Signature.sign.

Compute the signature

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
update(SessionContext
The SessionContext for calling this method - may be null if not called within a session context
session
,
byte[]
The hash data buffer
hash
,
int
Offset of hash data in buffer
off
,
int
Length of hash data
len
)

Implements org.apache.sshd.common.signature.Signature.update.

Update the computed signature with the given data

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

algorithmback to summary
private final String algorithm
signatureInstanceback to summary
private Signature signatureInstance

Constructor Detail

AbstractSignatureback to summary
protected AbstractSignature(String algorithm)

Method Detail

doInitSignatureback to summary
protected Signature doInitSignature(SessionContext session, String algo, Key key, boolean forSigning) throws GeneralSecurityException

Initializes the internal signature instance

Parameters
session:SessionContext

The SessionContext for calling this method - may be null if not called within a session context

algo:String

The signature's algorithm name

key:Key

the Key that is provided for initialization - a PrivateKey for signing and a PublicKey for verification

forSigning:boolean

If true then it is being initialized for signing, otherwise for verifying a signature

Returns:Signature

The java.security.Signature instance

Exceptions
GeneralSecurityException:
if failed to initialize
doVerifyback to summary
protected boolean doVerify(byte[] data) throws SignatureException
extractEncodedSignatureback to summary
protected Map.Entry<String, byte[]> extractEncodedSignature(byte[] sig, Collection<String> expectedTypes)

Makes an attempt to detect if the signature is encoded or pure data

Parameters
sig:byte[]

The original signature

expectedTypes:Collection<String>

The expected encoded key types

Returns:Map.Entry<String, byte[]>

A SimpleImmutableEntry where first value is the key type and second value is the data - null if not encoded

extractEncodedSignatureback to summary
protected Map.Entry<String, byte[]> extractEncodedSignature(byte[] sig, Predicate<? super String> typeSelector)
getAlgorithmback to summary
public final String getAlgorithm()

Implements org.apache.sshd.common.AlgorithmNameProvider.getAlgorithm.

Annotations
@Override
getSignatureback to summary
protected Signature getSignature()
Returns:Signature

The current java.security.Signature instance - null if not initialized

See Also
doInitSignature(SessionContext, String, Key, boolean)
initSignerback to summary
public void initSigner(SessionContext session, PrivateKey key) throws Exception

Implements org.apache.sshd.common.signature.Signature.initSigner.

Parameters
session:SessionContext

Doc from org.apache.sshd.common.signature.Signature.initSigner.

The SessionContext for calling this method - may be null if not called within a session context

key:PrivateKey

Doc from org.apache.sshd.common.signature.Signature.initSigner.

The PrivateKey to be used for signing

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.sshd.common.signature.Signature.initSigner.

If failed to initialize

initVerifierback to summary
public void initVerifier(SessionContext session, PublicKey key) throws Exception

Implements org.apache.sshd.common.signature.Signature.initVerifier.

Parameters
session:SessionContext

Doc from org.apache.sshd.common.signature.Signature.initVerifier.

The SessionContext for calling this method - may be null if not called within a session context

key:PublicKey

Doc from org.apache.sshd.common.signature.Signature.initVerifier.

The PublicKey to be used for verifying signatures

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.sshd.common.signature.Signature.initVerifier.

If failed to initialize

signback to summary
public byte[] sign(SessionContext session) throws Exception

Implements org.apache.sshd.common.signature.Signature.sign.

Doc from org.apache.sshd.common.signature.Signature.sign.

Compute the signature

Parameters
session:SessionContext

The SessionContext for calling this method - may be null if not called within a session context

Returns:byte[]

The signature value

Annotations
@Override
Exceptions
Exception:
If failed to calculate the signature
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateback to summary
public void update(SessionContext session, byte[] hash, int off, int len) throws Exception

Implements org.apache.sshd.common.signature.Signature.update.

Doc from org.apache.sshd.common.signature.Signature.update.

Update the computed signature with the given data

Parameters
session:SessionContext

The SessionContext for calling this method - may be null if not called within a session context

hash:byte[]

The hash data buffer

off:int

Offset of hash data in buffer

len:int

Length of hash data

Annotations
@Override
Exceptions
Exception:
If failed to update