Class IPCrypt

java.lang.Object
net.targetr.wtm3.io.IPCrypt

public class IPCrypt extends Object
Implementation of ipcrypt-deterministic using AES-128.
  • Method Details

    • encrypt

      public static String encrypt(String ip, byte[] key) throws Exception
      Encrypt an IP address using AES-128.
      Parameters:
      ip - The IP address to encrypt
      key - 16-byte encryption key
      Returns:
      Encrypted IP address
      Throws:
      Exception - if encryption fails
    • encrypt

      public static String encrypt(InetAddress ip, byte[] key) throws Exception
      Encrypt an IP address using AES-128.
      Parameters:
      ip - The IP address to encrypt
      key - 16-byte encryption key
      Returns:
      Encrypted IP address
      Throws:
      Exception - if encryption fails
    • ipToBytes

      public static byte[] ipToBytes(String ip) throws UnknownHostException
      Convert an IP address to its 16-byte representation.
      Parameters:
      ip - IP address as string
      Returns:
      16-byte representation
      Throws:
      UnknownHostException - if IP address is invalid
    • ipToBytes

      public static byte[] ipToBytes(InetAddress ip)
      Convert an IP address to its 16-byte representation.
      Parameters:
      ip - IP address as InetAddress
      Returns:
      16-byte representation
    • bytesToIp

      public static InetAddress bytesToIp(byte[] bytes16) throws UnknownHostException
      Convert a 16-byte representation back to an IP address.
      Parameters:
      bytes16 - 16-byte representation
      Returns:
      IP address as InetAddress
      Throws:
      UnknownHostException - if byte array is invalid
    • hexToBytes

      public static byte[] hexToBytes(String hex)
      Convert a hex string to byte array.
      Parameters:
      hex - Hex string
      Returns:
      Byte array
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Convert byte array to hex string.
      Parameters:
      bytes - Byte array
      Returns:
      Hex string
    • main

      public static void main(String[] args) throws Exception
      Utility main method to decrypt an IP Address with a key. Note, the active RCWeb server can not do this.
      Parameters:
      args - Command line arguments of IP Address to decrypt and key
      Throws:
      Exception - a problem with the address or key