Class CryptoEngine

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

public final class CryptoEngine extends Object
Core cryptographic primitives for CommuniDirect.
  • XOR cipher – fast, symmetric, key-stream based
  • Secure key generation via SecureRandom
  • Symmetric ASCII avatar – visual terminal identity derived from a key
All methods are stateless and thread-safe.
  • Method Details

    • xorTransform

      public static byte[] xorTransform(byte[] data, byte[] key)
      Applies a repeating XOR key-stream to data. The same call encrypts and decrypts (XOR is its own inverse).
      Parameters:
      data - non-null byte array to transform
      key - non-null, non-empty key; shorter keys are repeated cyclically
      Returns:
      a new byte array of the same length as data
      Throws:
      IllegalArgumentException - if data or key is null / empty
    • generateSecureKey

      public static byte[] generateSecureKey(int size)
      Generates a cryptographically-strong random key of the given size.
      Parameters:
      size - key length in bytes (must be > 0)
      Returns:
      freshly-generated key bytes
      Throws:
      IllegalArgumentException - if size is not positive
    • getSymmetricAvatar

      public static String getSymmetricAvatar(byte[] key)
      Derives a 5×5 symmetric ASCII art string from a key, suitable for terminal-based peer identification. Left and right halves mirror each other; the centre column is shared.
       Example output (5 rows × 5 cols, columns separated by spaces):
      
         # @ * @ #
         X O + O X
         = # @ # =
         X O + O X
         # @ * @ #
       
      Parameters:
      key - non-null, non-empty byte array used to seed the avatar pattern
      Returns:
      multi-line string representation of the avatar
      Throws:
      IllegalArgumentException - if key is null or empty