pub struct KeyStore { /* private fields */ }Expand description
Java KeyStore (JKS) implementation
A KeyStore is a mapping of alias to either a PrivateKeyEntry or TrustedCertificateEntry.
Implementations§
Source§impl KeyStore
impl KeyStore
Sourcepub fn with_options(options: KeyStoreOptions) -> Self
pub fn with_options(options: KeyStoreOptions) -> Self
Creates a new empty KeyStore with custom options
Sourcepub fn store<W: Write>(&self, w: W, password: &[u8]) -> Result<()>
pub fn store<W: Write>(&self, w: W, password: &[u8]) -> Result<()>
Writes the keystore to the writer with password-based signature
It is strongly recommended to zero out the password after use.
Sourcepub fn load<R: Read>(&mut self, r: R, password: &[u8]) -> Result<()>
pub fn load<R: Read>(&mut self, r: R, password: &[u8]) -> Result<()>
Reads a keystore from the reader and verifies its signature
It is strongly recommended to zero out the password after use.
Sourcepub fn load_auto_detect<R: Read>(
&mut self,
reader: R,
password: &[u8],
) -> Result<()>
pub fn load_auto_detect<R: Read>( &mut self, reader: R, password: &[u8], ) -> Result<()>
Auto-detect format and load keystore from reader
This method automatically detects whether the file is JKS or PKCS12 format and loads it accordingly. Supports:
- JKS format (
.jksfiles) - magic: 0xFEEDFEED - PKCS12 format (
.keystore,.p12,.pfxfiles) - starts with 0x30
It is strongly recommended to zero out the password after use.
Sourcepub fn set_private_key_entry(
&mut self,
alias: &str,
entry: PrivateKeyEntry,
password: &[u8],
) -> Result<()>
pub fn set_private_key_entry( &mut self, alias: &str, entry: PrivateKeyEntry, password: &[u8], ) -> Result<()>
Adds a PrivateKeyEntry encrypted with the password
It is strongly recommended to zero out the password after use.
Sourcepub fn get_private_key_entry(
&self,
alias: &str,
password: &[u8],
) -> Result<PrivateKeyEntry>
pub fn get_private_key_entry( &self, alias: &str, password: &[u8], ) -> Result<PrivateKeyEntry>
Returns and decrypts a PrivateKeyEntry with the password
It is strongly recommended to zero out the password after use.
Sourcepub fn get_raw_private_key_entry(&self, alias: &str) -> Result<PrivateKeyEntry>
pub fn get_raw_private_key_entry(&self, alias: &str) -> Result<PrivateKeyEntry>
Returns a PrivateKeyEntry without decryption (for already-decrypted keys like PKCS12)
This method returns the private key entry as-is, without attempting to decrypt it. Useful for keystores loaded from PKCS12 format where keys are already decrypted.
Sourcepub fn get_private_key_entry_certificate_chain(
&self,
alias: &str,
) -> Result<Vec<Certificate>>
pub fn get_private_key_entry_certificate_chain( &self, alias: &str, ) -> Result<Vec<Certificate>>
Returns the certificate chain associated with a PrivateKeyEntry
Sourcepub fn is_private_key_entry(&self, alias: &str) -> bool
pub fn is_private_key_entry(&self, alias: &str) -> bool
Returns true if the alias exists and is a PrivateKeyEntry
Sourcepub fn set_trusted_certificate_entry(
&mut self,
alias: &str,
entry: TrustedCertificateEntry,
) -> Result<()>
pub fn set_trusted_certificate_entry( &mut self, alias: &str, entry: TrustedCertificateEntry, ) -> Result<()>
Adds a TrustedCertificateEntry (not encrypted, just stored)
Sourcepub fn get_trusted_certificate_entry(
&self,
alias: &str,
) -> Result<TrustedCertificateEntry>
pub fn get_trusted_certificate_entry( &self, alias: &str, ) -> Result<TrustedCertificateEntry>
Returns a TrustedCertificateEntry
Sourcepub fn is_trusted_certificate_entry(&self, alias: &str) -> bool
pub fn is_trusted_certificate_entry(&self, alias: &str) -> bool
Returns true if the alias exists and is a TrustedCertificateEntry
Sourcepub fn delete_entry(&mut self, alias: &str)
pub fn delete_entry(&mut self, alias: &str)
Deletes an entry from the keystore