Class KeyGenerator

java.lang.Object
net.vincent.communidirect.common.crypto.KeyGenerator

public final class KeyGenerator extends Object
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 KeyStoreManager
 
The 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 Type
    Method
    Description
    static KeyPair
    Generates a fresh Ed25519 key pair, stores it on disk, writes keys.toml and returns the in-memory KeyPair.
    static byte[]
    toRaw32(byte[] spkiEncoded)
    Strips the 12-byte Ed25519 SPKI DER header from spkiEncoded (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 a PublicKey via X509EncodedKeySpec.

    Methods inherited from class java.lang.Object

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

    • generate

      public static KeyPair generate() throws Exception
      Generates a fresh Ed25519 key pair, stores it on disk, writes keys.toml and returns the in-memory KeyPair.
      Returns:
      the newly generated key pair
      Throws:
      Exception - on any IO or JCA error
    • toRaw32

      public static byte[] toRaw32(byte[] spkiEncoded)
      Strips the 12-byte Ed25519 SPKI DER header from spkiEncoded (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 a PublicKey via X509EncodedKeySpec.
      Parameters:
      raw32 - 32-byte raw Ed25519 public key
      Returns:
      44-byte SubjectPublicKeyInfo-encoded public key