Class SignatureUtil
- java.lang.Object
-
- com.github.toolarium.security.signature.SignatureUtil
-
public final class SignatureUtil extends java.lang.ObjectThis class implements a simple interface to sign data and verify the signed data. The class works with the standard API of java and use public and private keys.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SignatureUtilgetInstance()Get the instancebyte[]sign(java.lang.String provider, java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data)Sign data with the given algorithm and private key.byte[]sign(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data)Sign data with the given algorithm and private key.booleanverify(java.lang.String provider, java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith)Verify a signed data.booleanverify(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith)Verify a signed data.
-
-
-
Method Detail
-
getInstance
public static SignatureUtil getInstance()
Get the instance- Returns:
- the instance
-
verify
public boolean verify(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith) throws java.security.GeneralSecurityExceptionVerify a signed data.- Parameters:
algorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...publicKey- the public keydataToVerify- the data to verify the signaturedataToCompareWith- the data to compare with the signed data- Returns:
- true if the verification of the response is identical.
- Throws:
java.security.GeneralSecurityException- in case of error
-
verify
public boolean verify(java.lang.String provider, java.lang.String algorithm, java.security.PublicKey publicKey, byte[] dataToVerify, byte[] dataToCompareWith) throws java.security.GeneralSecurityExceptionVerify a signed data.- Parameters:
provider- the provideralgorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...publicKey- the public keydataToVerify- the data to verify the signaturedataToCompareWith- the data to compare with the signed data- Returns:
- true if the verification of the response is identical.
- Throws:
java.security.GeneralSecurityException- in case of error
-
sign
public byte[] sign(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data) throws java.security.GeneralSecurityExceptionSign data with the given algorithm and private key.- Parameters:
algorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...privateKey- the private keydata- the data to sign- Returns:
- the signed response
- Throws:
java.security.GeneralSecurityException- in case of error
-
sign
public byte[] sign(java.lang.String provider, java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] data) throws java.security.GeneralSecurityExceptionSign data with the given algorithm and private key.- Parameters:
provider- the provideralgorithm- the algorithm like: SHA1withRSA, SHA1withDSA, RSA...privateKey- the private keydata- the data to sign- Returns:
- the signed response
- Throws:
java.security.GeneralSecurityException- in case of error
-
-