Module java.base
Package java.security

Class KeyStore.PasswordProtection

java.lang.Object
java.security.KeyStore.PasswordProtection
所有已实现的接口:
KeyStore.ProtectionParameter, Destroyable
封装类:
KeyStore

public static class KeyStore.PasswordProtection extends Object implements KeyStore.ProtectionParameter, Destroyable
基于密码的ProtectionParameter实现。
自 JDK 版本:
1.5
  • Constructor Details

    • PasswordProtection

      public PasswordProtection(char[] password)
      创建一个密码参数。

      指定的password在存储到新的PasswordProtection对象之前会被克隆。

      参数:
      password - 密码,可以为null
    • PasswordProtection

      public PasswordProtection(char[] password, String protectionAlgorithm, AlgorithmParameterSpec protectionParameters)
      创建一个密码参数,并指定在加密密钥库条目时要使用的保护算法和相关参数。

      指定的password在存储到新的PasswordProtection对象之前会被克隆。

      参数:
      password - 密码,可以为null
      protectionAlgorithm - 加密算法名称,例如,PBEWithHmacSHA256AndAES_256。有关标准加密算法名称的信息,请参阅Java安全标准算法名称规范中的Cipher部分。
      protectionParameters - 加密算法参数规范,可以为null
      抛出:
      NullPointerException - 如果protectionAlgorithmnull
      自 JDK 版本:
      1.8
  • Method Details

    • getProtectionAlgorithm

      public String getProtectionAlgorithm()
      获取保护算法的名称。如果未设置任何算法,则密钥库提供程序将使用其默认的保护算法。
      返回:
      算法名称,如果未设置则为null
      自 JDK 版本:
      1.8
    • getProtectionParameters

      public AlgorithmParameterSpec getProtectionParameters()
      获取为保护算法提供的参数。
      返回:
      算法参数规范,如果未设置则为null
      自 JDK 版本:
      1.8
    • getPassword

      public char[] getPassword()
      获取密码。

      请注意,此方法返回密码的引用。如果创建了数组的克隆,则调用者有责任在不再需要密码信息后将其清零。

      返回:
      密码,可以为null
      抛出:
      IllegalStateException - 如果密码已被清除(销毁)
      参见:
    • destroy

      public void destroy() throws DestroyFailedException
      清除密码。
      指定者:
      destroy 在接口 Destroyable
      抛出:
      DestroyFailedException - 如果无法清除密码
    • isDestroyed

      public boolean isDestroyed()
      确定密码是否已被清除。
      指定者:
      isDestroyed 在接口 Destroyable
      返回:
      如果密码已被清除则返回true,否则返回false