Package rs.baselib.crypto
Class DataSigner
java.lang.Object
rs.baselib.crypto.DataSigner
public class DataSigner
extends java.lang.Object
The class for signing and verifying signatures.
- Author:
- ralph
-
Constructor Summary
Constructors Constructor Description DataSigner()Constructor.DataSigner(java.security.KeyPair keyPair)Constructor from key pair.DataSigner(java.security.PrivateKey privateKey)Constructor from private key.DataSigner(java.security.PrivateKey privateKey, java.security.PublicKey publicKey)Constructor from key pair.DataSigner(java.security.PublicKey publicKey)Constructor from public key. -
Method Summary
Modifier and Type Method Description byte[]getByteSignature(byte[] bytes)Creates a signature for the given bytes.byte[]getByteSignature(java.io.InputStream in)Creates a signature for the given stream.byte[]getByteSignature(java.io.Reader reader)Creates a signature for the given stream.byte[]getByteSignature(java.lang.String str)Creates a signature for the given string.java.security.PrivateKeygetPrivateKey()Returns the privateKey.java.security.PublicKeygetPublicKey()Returns the publicKey.voidsetPrivateKey(java.lang.String privateKey)Sets the privateKey.voidsetPrivateKey(java.security.PrivateKey privateKey)Sets the privateKey.voidsetPublicKey(java.lang.String publicKey)Sets the publicKey.voidsetPublicKey(java.security.PublicKey publicKey)Sets the publicKey.java.lang.Stringsign(byte[] bytes)Creates a signature for the given bytes.java.lang.Stringsign(java.io.InputStream in)Creates a signature for the given stream.java.lang.Stringsign(java.io.Reader reader)Creates a signature for the given stream.java.lang.Stringsign(java.lang.String str)Creates a signature for the given string.voidupdate(java.security.Signature signature, java.io.InputStream in)Updates the DSA with the bytes from this stream.protected voidupdate(java.security.Signature signature, java.io.Reader reader)Updates the DSA with the bytes from this stream.booleanverify(byte[] signature, byte[] data)Verifies the signature on the given bytes.booleanverify(byte[] signature, java.io.InputStream in)Verifies the signature on the given stream.booleanverify(byte[] signature, java.io.Reader in)Verifies the signature on the given stream.booleanverify(java.lang.String signature, java.io.InputStream in)Verifies the signature on the given stream.booleanverify(java.lang.String signature, java.io.Reader in)Verifies the signature on the given stream.booleanverify(java.lang.String signature, java.lang.String str)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
public DataSigner(java.security.PrivateKey privateKey, java.security.PublicKey publicKey) throws DecryptionExceptionConstructor 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
public java.security.PrivateKey getPrivateKey()Returns the privateKey.- Returns:
- the privateKey
-
setPrivateKey
public void setPrivateKey(java.security.PrivateKey privateKey)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
public java.security.PublicKey getPublicKey()Returns the publicKey.- Returns:
- the publicKey
-
setPublicKey
public void setPublicKey(java.security.PublicKey publicKey)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
public void update(java.security.Signature signature, java.io.InputStream in) throws SigningExceptionUpdates 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
protected void update(java.security.Signature signature, java.io.Reader reader) throws SigningExceptionUpdates 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
-