java.lang.Object
io.github.lunasaw.gb28181.common.entity.control.instruction.crypto.PTZInstructionCrypto

public class PTZInstructionCrypto extends Object
PTZ指令加密解密器 提供多种加密算法支持
  • Constructor Details

    • PTZInstructionCrypto

      public PTZInstructionCrypto()
  • Method Details

    • generateAESKey

      public static SecretKey generateAESKey(int keySize)
      生成AES密钥
      Parameters:
      keySize - 密钥长度 (128, 192, 256)
      Returns:
      AES密钥
    • generateAESKeyFromPassword

      public static SecretKey generateAESKeyFromPassword(String password)
      从密码生成AES密钥
      Parameters:
      password - 密码
      Returns:
      AES密钥
    • encryptAESGCM

      public static byte[] encryptAESGCM(PTZInstructionFormat instruction, SecretKey secretKey)
      AES-GCM加密
      Parameters:
      instruction - PTZ指令
      secretKey - 密钥
      Returns:
      加密结果 (包含IV + 密文 + 认证标签)
    • decryptAESGCM

      public static PTZInstructionFormat decryptAESGCM(byte[] encryptedData, SecretKey secretKey)
      AES-GCM解密
      Parameters:
      encryptedData - 加密数据 (包含IV + 密文 + 认证标签)
      secretKey - 密钥
      Returns:
      PTZ指令
    • encryptXOR

      public static byte[] encryptXOR(PTZInstructionFormat instruction, byte[] key)
      简单XOR加密 (适用于轻量级场景)
      Parameters:
      instruction - PTZ指令
      key - 密钥 (8字节)
      Returns:
      加密后的字节数组
    • decryptXOR

      public static PTZInstructionFormat decryptXOR(byte[] encryptedData, byte[] key)
      简单XOR解密
      Parameters:
      encryptedData - 加密数据
      key - 密钥 (8字节)
      Returns:
      PTZ指令
    • calculateMD5Hash

      public static byte[] calculateMD5Hash(PTZInstructionFormat instruction)
      计算指令数据的MD5哈希
      Parameters:
      instruction - PTZ指令
      Returns:
      MD5哈希值
    • calculateSHA256Hash

      public static byte[] calculateSHA256Hash(PTZInstructionFormat instruction)
      计算指令数据的SHA-256哈希
      Parameters:
      instruction - PTZ指令
      Returns:
      SHA-256哈希值
    • verifyIntegrity

      public static boolean verifyIntegrity(PTZInstructionFormat instruction, byte[] expectedHash, String algorithm)
      验证指令完整性
      Parameters:
      instruction - PTZ指令
      expectedHash - 期望的哈希值
      algorithm - 哈希算法 ("MD5" 或 "SHA-256")
      Returns:
      是否一致
    • generateRandomKey

      public static byte[] generateRandomKey(int length)
      生成安全的随机密钥
      Parameters:
      length - 密钥长度
      Returns:
      随机密钥