Class SecureKeyStore
java.lang.Object
cloud.opencode.base.crypto.key.SecureKeyStore
- All Implemented Interfaces:
AutoCloseable
Secure key store for managing cryptographic keys - Store and retrieve keys securely using PKCS12 format
安全密钥存储 - 使用 PKCS12 格式安全地存储和检索密钥
Features | 主要功能:
- In-memory secure key storage - 内存安全密钥存储
- Key lifecycle management - 密钥生命周期管理
Usage Examples | 使用示例:
SecureKeyStore store = SecureKeyStore.create();
store.store("myKey", secretKey);
SecretKey key = store.load("myKey");
Security | 安全性:
- Thread-safe: No - 线程安全: 否
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaliases()Get all aliases in key store 获取密钥存储中的所有别名voidclose()Close the key store and clear sensitive data 关闭密钥存储并清除敏感数据booleancontainsAlias(String alias) Check if key store contains entry with given alias 检查密钥存储是否包含给定别名的条目static SecureKeyStorecreate()Create a new empty key store 创建新的空密钥存储voiddeleteEntry(String alias) Delete entry from key store 从密钥存储中删除条目getKeyPair(String alias, char[] password) Get key pair from key store 从密钥存储中获取密钥对getPrivateKey(String alias, char[] password) Get private key from key store 从密钥存储中获取私钥getPublicKey(String alias) Get public key from key store 从密钥存储中获取公钥getSecretKey(String alias, char[] password) Get secret key from key store 从密钥存储中获取对称密钥static SecureKeyStoreLoad key store from file 从文件加载密钥存储voidSave key store to file 保存密钥存储到文件voidStore key pair in key store 在密钥存储中存储密钥对voidstore(String alias, PrivateKey privateKey, char[] password, Certificate[] chain) Store private key with certificate chain in key store 在密钥存储中存储带证书链的私钥voidStore secret key in key store 在密钥存储中存储对称密钥
-
Method Details
-
create
Create a new empty key store 创建新的空密钥存储- Returns:
- new SecureKeyStore instance
- Throws:
OpenKeyException- if creation fails
-
load
Load key store from file 从文件加载密钥存储- Parameters:
path- path to key store filepassword- password to unlock key store- Returns:
- loaded SecureKeyStore instance
- Throws:
OpenKeyException- if loading fails
-
store
Store secret key in key store 在密钥存储中存储对称密钥- Parameters:
alias- alias for the keykey- secret key to storepassword- password to protect the key- Throws:
OpenKeyException- if storing fails
-
store
Store key pair in key store 在密钥存储中存储密钥对- Parameters:
alias- alias for the key pairkeyPair- key pair to storepassword- password to protect the private key- Throws:
OpenKeyException- if storing fails
-
store
Store private key with certificate chain in key store 在密钥存储中存储带证书链的私钥- Parameters:
alias- alias for the keyprivateKey- private key to storepassword- password to protect the private keychain- certificate chain- Throws:
OpenKeyException- if storing fails
-
getSecretKey
Get secret key from key store 从密钥存储中获取对称密钥- Parameters:
alias- alias of the keypassword- password to unlock the key- Returns:
- secret key
- Throws:
OpenKeyException- if retrieval fails or key not found
-
getKeyPair
Get key pair from key store 从密钥存储中获取密钥对- Parameters:
alias- alias of the key pairpassword- password to unlock the private key- Returns:
- key pair
- Throws:
OpenKeyException- if retrieval fails or key not found
-
getPrivateKey
Get private key from key store 从密钥存储中获取私钥- Parameters:
alias- alias of the keypassword- password to unlock the private key- Returns:
- private key
- Throws:
OpenKeyException- if retrieval fails or key not found
-
getPublicKey
Get public key from key store 从密钥存储中获取公钥- Parameters:
alias- alias of the key- Returns:
- public key
- Throws:
OpenKeyException- if retrieval fails or key not found
-
containsAlias
Check if key store contains entry with given alias 检查密钥存储是否包含给定别名的条目- Parameters:
alias- alias to check- Returns:
- true if alias exists
- Throws:
OpenKeyException- if check fails
-
deleteEntry
Delete entry from key store 从密钥存储中删除条目- Parameters:
alias- alias of the entry to delete- Throws:
OpenKeyException- if deletion fails
-
aliases
Get all aliases in key store 获取密钥存储中的所有别名- Returns:
- set of aliases
- Throws:
OpenKeyException- if retrieval fails
-
save
Save key store to file 保存密钥存储到文件- Parameters:
path- path to save the key storepassword- password to protect the key store- Throws:
OpenKeyException- if saving fails
-
close
public void close()Close the key store and clear sensitive data 关闭密钥存储并清除敏感数据- Specified by:
closein interfaceAutoCloseable
-