public class DigitalSignature
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
ALGORITHM
The algorithm used for signing the values, corresponds to the server certificate algo.
|
private java.security.PrivateKey |
privateKey
Private key
|
private java.security.PublicKey |
publicKey
Public key
|
| Constructor and Description |
|---|
DigitalSignature(java.security.PrivateKey privateKey,
java.security.PublicKey publicKey)
Public constructor accepting private : public key pair.
|
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
fromHex(java.lang.String hexText)
Converts a hex formatted string back to a byte array.
|
static DigitalSignature |
fromServerKeyStore()
Reads the server key store, retrieves the public and private key pair and returns an instance of
DigitalSignature. |
static void |
main(java.lang.String[] args)
Test for signing messages.
|
byte[] |
sign(java.lang.String message)
Signs the message with the private key and returns the signed value.
|
static java.lang.String |
toHex(byte[] bytes)
Converts a byte array into a hex format.
|
boolean |
verify(java.lang.String originalMessage,
byte[] signedMessage)
Signs the message with the private key and returns the signed value.
|
private static final java.lang.String ALGORITHM
private final java.security.PrivateKey privateKey
private final java.security.PublicKey publicKey
public DigitalSignature(java.security.PrivateKey privateKey,
java.security.PublicKey publicKey)
privateKey - Private key.publicKey - Public key.public static DigitalSignature fromServerKeyStore() throws java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.NoSuchAlgorithmException, java.io.IOException, java.security.cert.CertificateException
DigitalSignature.DigitalSignature with the public and private key pair for the server.java.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionjava.security.cert.CertificateExceptionpublic static java.lang.String toHex(byte[] bytes)
bytes - The byte array to be converted.public static byte[] fromHex(java.lang.String hexText)
hexText - Hex formatted string.public byte[] sign(java.lang.String message)
throws java.security.SignatureException,
java.security.InvalidKeyException,
java.security.NoSuchAlgorithmException
message - The message to sign.java.security.SignatureExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionpublic boolean verify(java.lang.String originalMessage,
byte[] signedMessage)
throws java.security.SignatureException,
java.security.InvalidKeyException,
java.security.NoSuchAlgorithmException
originalMessage - The original message.signedMessage - The signed message.true if the signedMessage is generated by the key, false otherwise.java.security.SignatureExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionpublic static void main(java.lang.String[] args)
throws java.lang.Exception
args - Unused.java.lang.Exception