Class CryptoJDK.Signature

java.lang.Object
com.barbantfintech.tools.common.cryptojdk.CryptoJDK.Signature
Enclosing class:
CryptoJDK

public static class CryptoJDK.Signature extends Object
This class provides functionality to generate and verify cryptographic signatures using private keys. This is crucial for verifying the authenticity and integrity of messages in blockchain applications.

Example usage:

 
 // Signing a message
 String signature = CryptoJDK.Signature.generate(network, addressType, privateKey, message);

 // Verifying a signature
 boolean isValid = CryptoJDK.Signature.verify(network, address, message, signature);
 
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    generate(@NonNull Network network, @NonNull AddressType addressType, @NonNull String privateKey, @NonNull String message)
    Generates a cryptographic signature for a given message using a specified private key.
    static boolean
    verify(@NonNull Network network, @NonNull String address, @NonNull String message, @NonNull String signature)
    Verifies the authenticity of a given message signature, ensuring it was signed using the private key associated with a specified blockchain address.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Signature

      public Signature()
  • Method Details

    • generate

      public static String generate(@NonNull @NonNull Network network, @NonNull @NonNull AddressType addressType, @NonNull @NonNull String privateKey, @NonNull @NonNull String message) throws CryptoJDKException
      Generates a cryptographic signature for a given message using a specified private key. This method is typically used to sign messages that need to be securely authenticated.
      Parameters:
      network - The blockchain network context within which the signing occurs (e.g., Bitcoin, Ethereum).
      addressType - The type of blockchain address associated with the private key.
      privateKey - The private key used to sign the message. This key must correspond to the address type.
      message - The raw text message to be signed.
      Returns:
      A string representing the generated signature.
      Throws:
      CryptoJDKException - If an error occurs during the signing process, such as an invalid key or network.
    • verify

      public static boolean verify(@NonNull @NonNull Network network, @NonNull @NonNull String address, @NonNull @NonNull String message, @NonNull @NonNull String signature) throws CryptoJDKException
      Verifies the authenticity of a given message signature, ensuring it was signed using the private key associated with a specified blockchain address.
      Parameters:
      network - The blockchain network context within which the verification occurs (e.g., Bitcoin, Ethereum).
      address - The blockchain address associated with the private key that purportedly signed the message.
      message - The raw text message that was signed.
      signature - The signature that needs to be verified.
      Returns:
      true if the signature is valid and the message was indeed signed by the private key associated with the provided address; false otherwise.
      Throws:
      CryptoJDKException - If an error occurs during the verification process, such as an invalid signature or network.