Class SunPkcs11PrivateKeyAccessor

java.lang.Object
se.swedenconnect.security.credential.pkcs11.SunPkcs11PrivateKeyAccessor
All Implemented Interfaces:
Pkcs11ObjectAccessor<PrivateKey>, Pkcs11PrivateKeyAccessor

public class SunPkcs11PrivateKeyAccessor extends Object implements Pkcs11PrivateKeyAccessor
An implementation of the Pkcs11PrivateKeyAccessor interface for the SunPKCS11 security provider and other providers that implement the Java KeyStoreSpi.
Author:
Martin Lindström
  • Constructor Details

    • SunPkcs11PrivateKeyAccessor

      public SunPkcs11PrivateKeyAccessor()
  • Method Details

    • get

      @Nonnull public PrivateKey get(@Nonnull Provider provider, @Nonnull String alias, @Nonnull char[] pin) throws SecurityException
      Gets a reference to the private key from the PKCS#11 device, and throws SecurityException if it can not be extracted or is not found.
      Specified by:
      get in interface Pkcs11ObjectAccessor<PrivateKey>
      Specified by:
      get in interface Pkcs11PrivateKeyAccessor
      Parameters:
      provider - the security provider to use
      alias - the alias to the entry holding the object
      pin - the PIN needed to access the entry
      Returns:
      an object reference or null if the object is not available
      Throws:
      SecurityException - if the operation is not successful
    • get

      @Nullable public PrivateKey get(@Nonnull KeyStore keyStore, @Nonnull String alias, @Nonnull char[] pin) throws KeyStoreException
      Gets the private key from the given entry (identified by alias).
      Parameters:
      keyStore - the keystore
      alias - the entry alias
      pin - the PIN to unlock the key
      Returns:
      a PrivateKey or null if no key is found
      Throws:
      KeyStoreException - for errors accessing the key