Package rs.baselib.crypto
Class DataSigner
java.lang.Object
rs.baselib.crypto.DataSigner
The class for signing and verifying signatures.
- Author:
- ralph
-
Constructor Summary
ConstructorDescriptionConstructor.DataSigner
(KeyPair keyPair) Constructor from key pair.DataSigner
(PrivateKey privateKey) Constructor from private key.DataSigner
(PrivateKey privateKey, PublicKey publicKey) Constructor from key pair.DataSigner
(PublicKey publicKey) Constructor from public key. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getByteSignature
(byte[] bytes) Creates a signature for the given bytes.byte[]
Creates a signature for the given stream.byte[]
getByteSignature
(Reader reader) Creates a signature for the given stream.byte[]
getByteSignature
(String str) Creates a signature for the given string.Returns the privateKey.Returns the publicKey.void
setPrivateKey
(String privateKey) Sets the privateKey.void
setPrivateKey
(PrivateKey privateKey) Sets the privateKey.void
setPublicKey
(String publicKey) Sets the publicKey.void
setPublicKey
(PublicKey publicKey) Sets the publicKey.sign
(byte[] bytes) Creates a signature for the given bytes.sign
(InputStream in) Creates a signature for the given stream.Creates a signature for the given stream.Creates a signature for the given string.void
update
(Signature signature, InputStream in) Updates the DSA with the bytes from this stream.protected void
Updates the DSA with the bytes from this stream.boolean
verify
(byte[] signature, byte[] data) Verifies the signature on the given bytes.boolean
verify
(byte[] signature, InputStream in) Verifies the signature on the given stream.boolean
Verifies the signature on the given stream.boolean
verify
(String signature, InputStream in) Verifies the signature on the given stream.boolean
Verifies the signature on the given stream.boolean
Verifies the signature on the given string.
-
Constructor Details
-
DataSigner
Constructor.- Throws:
DecryptionException
- - when a problem occurs
-
DataSigner
Constructor from key pair.- Parameters:
keyPair
- the key pair to be used- Throws:
DecryptionException
- - when a problem occurs
-
DataSigner
Constructor from key pair.- Parameters:
privateKey
- private keypublicKey
- public key- Throws:
DecryptionException
- - when a problem occurs
-
DataSigner
Constructor from private key.- Parameters:
privateKey
- the private key to be used- Throws:
DecryptionException
- - when a problem occurs
-
DataSigner
Constructor from public key.- Parameters:
publicKey
- the public key to be used- Throws:
DecryptionException
- - when a problem occurs
-
-
Method Details
-
getPrivateKey
Returns the privateKey.- Returns:
- the privateKey
-
setPrivateKey
Sets the privateKey.- Parameters:
privateKey
- the privateKey to set
-
setPrivateKey
Sets the privateKey.- Parameters:
privateKey
- the privateKey to set- Throws:
SigningException
- - when a problem occurs
-
getPublicKey
Returns the publicKey.- Returns:
- the publicKey
-
setPublicKey
Sets the publicKey.- Parameters:
publicKey
- the publicKey to set
-
setPublicKey
Sets the publicKey.- Parameters:
publicKey
- the publicKey to set- Throws:
SigningException
- - when a problem occurs
-
sign
Creates a signature for the given stream.- Parameters:
reader
- stream to be signed- Returns:
- signature of the provided stream
- Throws:
SigningException
- - when a problem occurs
-
getByteSignature
Creates a signature for the given stream.- Parameters:
reader
- stream to be signed- Returns:
- signature of the provided stream
- Throws:
SigningException
- - when a problem occurs
-
sign
Creates a signature for the given stream.- Parameters:
in
- stream to be signed- Returns:
- signature of the provided stream
- Throws:
SigningException
- - when a problem occurs
-
getByteSignature
Creates a signature for the given stream.- Parameters:
in
- stream to be signed- Returns:
- signature of the provided stream
- Throws:
SigningException
- - when a problem occurs
-
update
Updates the DSA with the bytes from this stream.- Parameters:
signature
- signaturein
- input stream- Throws:
SigningException
- when the stream cannot be signedSigningException
- - when a problem occurs
-
update
Updates the DSA with the bytes from this stream.- Parameters:
signature
- signaturereader
- reader for the input stream- Throws:
SigningException
- when the signing process fails
-
sign
Creates a signature for the given string.- Parameters:
str
- string to be signed- Returns:
- signature of the provided String
- Throws:
SigningException
- when the stream cannot be signed
-
getByteSignature
Creates a signature for the given string.- Parameters:
str
- string to be signed- Returns:
- signature of the provided String
- Throws:
SigningException
- when the stream cannot be signed
-
sign
Creates a signature for the given bytes.- Parameters:
bytes
- bytes to be signed- Returns:
- signature of the provided bytes
- Throws:
SigningException
- when the bytes cannot be signed
-
getByteSignature
Creates a signature for the given bytes.- Parameters:
bytes
- bytes to be signed- Returns:
- signature of the provided bytes
- Throws:
SigningException
- when the bytes cannot be signed
-
verify
Verifies the signature on the given stream.- Parameters:
signature
- signaturein
- stream to be verified- Returns:
- true if the signature confirms stream integrity
- Throws:
SigningException
- when the signature cannot be verified
-
verify
Verifies the signature on the given stream.- Parameters:
signature
- signaturein
- stream to be verified- Returns:
- true if the signature confirms stream integrity
- Throws:
SigningException
- when the signature cannot be verified
-
verify
Verifies the signature on the given stream.- Parameters:
signature
- signaturein
- stream to be verified- Returns:
- true if the signature confirms stream integrity
- Throws:
SigningException
- when the signature cannot be verified
-
verify
Verifies the signature on the given stream.- Parameters:
signature
- signaturein
- stream to be verified- Returns:
- true if the signature confirms stream integrity
- Throws:
SigningException
- when the signature cannot be verified
-
verify
Verifies the signature on the given string.- Parameters:
signature
- signaturestr
- string to be verified- Returns:
- true if the signature confirms string integrity
- Throws:
SigningException
- when the signature cannot be verified
-
verify
Verifies the signature on the given bytes.- Parameters:
signature
- signaturedata
- bytes to be verified- Returns:
- true if the signature confirms data integrity
- Throws:
SigningException
- when the signature cannot be verified
-