Class KeyGenerator
java.lang.Object
net.vincent.communidirect.common.crypto.KeyGenerator
Generates an Ed25519 identity key pair and persists it under
~/.communidirect/.
~/.communidirect/identity.key – PKCS8 DER private key (chmod 600) ~/.communidirect/keys/self.pub – 32-byte raw Ed25519 public key ~/.communidirect/keys.toml – path manifest consumed by KeyStoreManagerThe class is also the single source of truth for the encode/decode helpers that convert between Java's 44-byte SubjectPublicKeyInfo DER form and the 32-byte raw wire form required by the CDIR protocol.
-
Method Summary
Modifier and TypeMethodDescriptionstatic KeyPairgenerate()Generates a fresh Ed25519 key pair, stores it on disk, writeskeys.tomland returns the in-memoryKeyPair.static byte[]toRaw32(byte[] spkiEncoded) Strips the 12-byte Ed25519 SPKI DER header fromspkiEncoded(44 bytes) and returns the 32 raw key bytes suitable for wire transfer or direct file storage.static byte[]toSpki(byte[] raw32) Prepends the fixed 12-byte Ed25519 SPKI DER header to 32 raw key bytes so that JCA can reconstruct aPublicKeyviaX509EncodedKeySpec.
-
Method Details
-
generate
-
toRaw32
public static byte[] toRaw32(byte[] spkiEncoded) Strips the 12-byte Ed25519 SPKI DER header fromspkiEncoded(44 bytes) and returns the 32 raw key bytes suitable for wire transfer or direct file storage.- Parameters:
spkiEncoded- 44-byte SubjectPublicKeyInfo-encoded public key- Returns:
- 32 raw Ed25519 public key bytes
-
toSpki
public static byte[] toSpki(byte[] raw32) Prepends the fixed 12-byte Ed25519 SPKI DER header to 32 raw key bytes so that JCA can reconstruct aPublicKeyviaX509EncodedKeySpec.- Parameters:
raw32- 32-byte raw Ed25519 public key- Returns:
- 44-byte SubjectPublicKeyInfo-encoded public key
-