Class ECKeyPair

java.lang.Object
com.privatechain.crypto.ECKeyPair

public final class ECKeyPair extends Object
Immutable record holding an elliptic-curve key pair generated on the secp256k1 curve.

Instances are created exclusively by KeyPairGenerator.generateECKeyPair() or reconstructed from a hex-encoded private key via KeyPairGenerator.fromPrivateKeyHex(String). Consumer code should treat this object as an opaque credential holder and never log, serialize, or transmit it in plain form.

Security invariants

  • toString() never reveals the private key (NFR-SEC-01). The private-key field is rendered as [REDACTED].
  • getPrivateKeyHex() exists for legitimate export flows (e.g., keystore serialisation) but callers must protect the returned value.

 ECKeyPair keyPair = KeyPairGenerator.generateECKeyPair();
 String     pubHex  = keyPair.getPublicKeyHex();   // safe to share
 String     privHex = keyPair.getPrivateKeyHex();  // handle with care
 
Since:
1.0.0
See Also:
  • Method Details

    • getPublicKey

      public PublicKey getPublicKey()
      Returns the JCA PublicKey for this key pair.

      The public key may be shared freely; it is used to verify ECDSA signatures and to derive blockchain addresses.

      Returns:
      non-null public key
    • getPublicKeyHex

      public String getPublicKeyHex()
      Returns the uncompressed, DER-encoded public key as a lowercase hex string.

      The hex representation is the canonical form used in peer announcements and address derivation.

      Returns:
      130-character (65-byte, uncompressed point) hex string
    • getPrivateKeyHex

      public String getPrivateKeyHex()
      Returns the PKCS#8-encoded private key as a lowercase hex string.

      Warning: this value is a secret. The caller is responsible for zeroing the returned String from memory after use where possible. Only invoke this method in trusted, controlled code paths such as keystore encryption.

      Returns:
      hex-encoded private key bytes
    • toString

      public String toString()
      Returns a safe, human-readable summary of this key pair.

      The private key is never included in the output (NFR-SEC-01). The public key is truncated to its first 16 hex characters to keep log lines concise.

      Overrides:
      toString in class Object
      Returns:
      string in the form ECKeyPair{pub=<first16hex>..., priv=[REDACTED]}
    • equals

      public boolean equals(Object obj)

      Equality is determined by the raw encoding of both keys so that two ECKeyPair instances built from the same hex private key are considered equal.

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object