Class ECKeyPair
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 Summary
Modifier and TypeMethodDescriptionbooleanReturns the PKCS#8-encoded private key as a lowercase hex string.Returns the JCAPublicKeyfor this key pair.Returns the uncompressed, DER-encoded public key as a lowercase hex string.inthashCode()toString()Returns a safe, human-readable summary of this key pair.
-
Method Details
-
getPublicKey
Returns the JCAPublicKeyfor 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
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
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
Stringfrom 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
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.
-
equals
Equality is determined by the raw encoding of both keys so that two
ECKeyPairinstances built from the same hex private key are considered equal. -
hashCode
public int hashCode()
-