Class KeyUtil
java.lang.Object
cloud.opencode.base.crypto.key.KeyUtil
Key utility class for key operations and queries - Utility methods for working with cryptographic keys
密钥工具类 - 密钥操作和查询的实用方法
Features | 主要功能:
- Key conversion and encoding utilities - 密钥转换和编码工具
Usage Examples | 使用示例:
byte[] encoded = KeyUtil.encode(key);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
Performance | 性能特性:
- Time complexity: O(1) - 时间复杂度: O(1)
- Space complexity: O(k) - 空间复杂度: O(k),k为密钥大小
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetAlgorithm(Key key) Get key algorithm 获取密钥算法static byte[]getEncoded(Key key) Get encoded key bytes 获取编码的密钥字节static StringGet key format 获取密钥格式static intgetKeySize(Key key) Get key size in bits 获取密钥大小(位)static booleanisPrivateKey(Key key) Check if key is a private key 检查密钥是否为私钥static booleanisPublicKey(Key key) Check if key is a public key 检查密钥是否为公钥static booleanisSecretKey(Key key) Check if key is a secret key 检查密钥是否为对称密钥
-
Method Details
-
getKeySize
Get key size in bits 获取密钥大小(位)- Parameters:
key- the key to check- Returns:
- key size in bits
- Throws:
OpenKeyException- if key size cannot be determined
-
getAlgorithm
Get key algorithm 获取密钥算法- Parameters:
key- the key to check- Returns:
- algorithm name
- Throws:
OpenKeyException- if key is null
-
isPrivateKey
Check if key is a private key 检查密钥是否为私钥- Parameters:
key- the key to check- Returns:
- true if key is a private key
- Throws:
OpenKeyException- if key is null
-
isPublicKey
Check if key is a public key 检查密钥是否为公钥- Parameters:
key- the key to check- Returns:
- true if key is a public key
- Throws:
OpenKeyException- if key is null
-
isSecretKey
Check if key is a secret key 检查密钥是否为对称密钥- Parameters:
key- the key to check- Returns:
- true if key is a secret key
- Throws:
OpenKeyException- if key is null
-
getEncoded
Get encoded key bytes 获取编码的密钥字节- Parameters:
key- the key to encode- Returns:
- encoded key bytes
- Throws:
OpenKeyException- if key is null or encoding fails
-
getFormat
Get key format 获取密钥格式- Parameters:
key- the key to check- Returns:
- key format (e.g., "X.509", "PKCS#8", "RAW")
- Throws:
OpenKeyException- if key is null
-