Class CryptoEngine
java.lang.Object
net.vincent.communidirect.common.crypto.CryptoEngine
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]generateSecureKey(int size) Generates a cryptographically-strong random key of the given size.static StringgetSymmetricAvatar(byte[] key) Derives a 5×5 symmetric ASCII art string from a key, suitable for terminal-based peer identification.static byte[]xorTransform(byte[] data, byte[] key) Applies a repeating XOR key-stream todata.
-
Method Details
-
xorTransform
public static byte[] xorTransform(byte[] data, byte[] key) Applies a repeating XOR key-stream todata. The same call encrypts and decrypts (XOR is its own inverse).- Parameters:
data- non-null byte array to transformkey- non-null, non-empty key; shorter keys are repeated cyclically- Returns:
- a new byte array of the same length as
data - Throws:
IllegalArgumentException- ifdataorkeyis 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- ifsizeis not positive
-
getSymmetricAvatar
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- ifkeyis null or empty
-