Class PTZInstructionCrypto
java.lang.Object
io.github.lunasaw.gb28181.common.entity.control.instruction.crypto.PTZInstructionCrypto
PTZ指令加密解密器
提供多种加密算法支持
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
带认证的加密结果static enum
加密算法枚举 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
calculateMD5Hash
(PTZInstructionFormat instruction) 计算指令数据的MD5哈希static byte[]
calculateSHA256Hash
(PTZInstructionFormat instruction) 计算指令数据的SHA-256哈希static PTZInstructionFormat
decryptAESGCM
(byte[] encryptedData, SecretKey secretKey) AES-GCM解密static PTZInstructionFormat
decryptXOR
(byte[] encryptedData, byte[] key) 简单XOR解密static byte[]
encryptAESGCM
(PTZInstructionFormat instruction, SecretKey secretKey) AES-GCM加密static byte[]
encryptXOR
(PTZInstructionFormat instruction, byte[] key) 简单XOR加密 (适用于轻量级场景)static SecretKey
generateAESKey
(int keySize) 生成AES密钥static SecretKey
generateAESKeyFromPassword
(String password) 从密码生成AES密钥static byte[]
generateRandomKey
(int length) 生成安全的随机密钥static boolean
verifyIntegrity
(PTZInstructionFormat instruction, byte[] expectedHash, String algorithm) 验证指令完整性
-
Constructor Details
-
PTZInstructionCrypto
public PTZInstructionCrypto()
-
-
Method Details
-
generateAESKey
生成AES密钥- Parameters:
keySize
- 密钥长度 (128, 192, 256)- Returns:
- AES密钥
-
generateAESKeyFromPassword
从密码生成AES密钥- Parameters:
password
- 密码- Returns:
- AES密钥
-
encryptAESGCM
AES-GCM加密- Parameters:
instruction
- PTZ指令secretKey
- 密钥- Returns:
- 加密结果 (包含IV + 密文 + 认证标签)
-
decryptAESGCM
AES-GCM解密- Parameters:
encryptedData
- 加密数据 (包含IV + 密文 + 认证标签)secretKey
- 密钥- Returns:
- PTZ指令
-
encryptXOR
简单XOR加密 (适用于轻量级场景)- Parameters:
instruction
- PTZ指令key
- 密钥 (8字节)- Returns:
- 加密后的字节数组
-
decryptXOR
简单XOR解密- Parameters:
encryptedData
- 加密数据key
- 密钥 (8字节)- Returns:
- PTZ指令
-
calculateMD5Hash
计算指令数据的MD5哈希- Parameters:
instruction
- PTZ指令- Returns:
- MD5哈希值
-
calculateSHA256Hash
计算指令数据的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:
- 随机密钥
-