Interface CryptoToken

  • All Known Implementing Classes:
    PK11Token

    public interface CryptoToken
    A CryptoToken performs cryptographic operations and stores cryptographic items, such as keys and certs. It corresponds to a Cryptographic Service Provider (CSP) in CDSA, and to a PKCS #11 token.

    Instances of CryptoToken are obtained from CryptoManager.

    See Also:
    CryptoManager
    • Method Detail

      • getSignatureContext

        Signature getSignatureContext​(SignatureAlgorithm algorithm)
                               throws java.security.NoSuchAlgorithmException,
                                      TokenException
        Creates a Signature object, which can perform signing and signature verification. Signing and verification cryptographic operations will take place on this token. The signing key must be located on this token.
        Parameters:
        algorithm - The algorithm used for the signing/verification.
        Throws:
        java.security.NoSuchAlgorithmException - If the given algorithm is not supported by this provider.
        TokenException
      • getDigestContext

        JSSMessageDigest getDigestContext​(DigestAlgorithm algorithm)
                                   throws java.security.NoSuchAlgorithmException,
                                          java.security.DigestException
        Creates a Digest object. Digesting cryptographic operations will take place on this token.
        Parameters:
        algorithm - The algorithm used for digesting.
        Throws:
        java.security.NoSuchAlgorithmException - If this provider does not support the given algorithm.
        java.security.DigestException
      • getCipherContext

        Cipher getCipherContext​(EncryptionAlgorithm algorithm)
                         throws java.security.NoSuchAlgorithmException,
                                TokenException
        Creates a Cipher object, which can be used for encryption and decryption. Cryptographic operations will take place on this token. The keys used in the operations must be located on this token.
        Parameters:
        algorithm - The algorithm used for encryption/decryption.
        Throws:
        java.security.NoSuchAlgorithmException - If this provider does not support the given algorithm.
        TokenException
      • getKeyGenerator

        KeyGenerator getKeyGenerator​(KeyGenAlgorithm algorithm)
                              throws java.security.NoSuchAlgorithmException,
                                     TokenException
        Creates a KeyGenerator object, which can be used to generate symmetric encryption keys. Any keys generated with this KeyGenerator will be generated on this token.
        Parameters:
        algorithm - The algorithm that the keys will be used with.
        Throws:
        java.security.NoSuchAlgorithmException - If this token does not support the given algorithm.
        TokenException
      • getKeyPairGenerator

        KeyPairGenerator getKeyPairGenerator​(KeyPairAlgorithm algorithm)
                                      throws java.security.NoSuchAlgorithmException,
                                             TokenException
        Creates a KeyPairGenerator object, which can be used to generate key pairs. Any keypairs generated with this generator will be generated on this token.
        Parameters:
        algorithm - The algorithm that the keys will be used with (RSA, DSA, EC, etc.)
        Throws:
        java.security.NoSuchAlgorithmException - If this token does not support the given algorithm.
        TokenException
      • generateCertRequest

        java.lang.String generateCertRequest​(java.lang.String subject,
                                             int keysize,
                                             java.lang.String keyType,
                                             byte[] P,
                                             byte[] Q,
                                             byte[] G)
                                      throws TokenException,
                                             java.security.InvalidParameterException,
                                             PQGParamGenException
        Generates a b64 encoded PKCS10 blob used for making cert request. Begin/End brackets included.
        Parameters:
        subject - subject dn of the certificate
        keysize - size of the key
        keyType - "rsa" or "dsa"
        P - The DSA prime parameter
        Q - The DSA sub-prime parameter
        G - The DSA base parameter
        Returns:
        base64 encoded pkcs10 certificate request with Begin/end brackets
        Throws:
        TokenException
        java.security.InvalidParameterException
        PQGParamGenException
      • doesAlgorithm

        boolean doesAlgorithm​(Algorithm alg)
        Determines whether this token supports the given algorithm.
        Parameters:
        alg - A JSS algorithm. Note that for Signature, a token may fail to support a specific SignatureAlgorithm (such as RSASignatureWithMD5Digest) even though it does support the generic algorithm (RSASignature). In this case, the signature operation will be performed on that token, but the digest operation will be performed on the internal token.
        Returns:
        true if the token supports the algorithm.
      • getLoginTimeoutMinutes

        int getLoginTimeoutMinutes()
                            throws TokenException
        Returns the login timeout period. The timeout is only used if the login mode is TIMEOUT.
        Throws:
        TokenException - If an error occurs on the token.
        See Also:
        getLoginMode()
      • setLoginTimeoutMinutes

        void setLoginTimeoutMinutes​(int timeoutMinutes)
                             throws TokenException
        Sets the timeout period for logging in. This will only be used if the login mode is TIMEOUT.
        Throws:
        TokenException - If timeouts are not supported by this token, or an error occurs on the token.
        See Also:
        setLoginMode(int)
      • passwordIsInitialized

        boolean passwordIsInitialized()
                               throws TokenException
        Determine whether the password has been initialized yet. Some tokens (such as the Netscape Internal Key Token) don't allow initializing the PIN more than once.
        Throws:
        TokenException - If an error occurs on the token.
      • getName

        java.lang.String getName()
                          throws TokenException
        Obtain the nickname, or label, of this token.
        Throws:
        TokenException - If an error occurs on the token.
      • getCryptoStore

        CryptoStore getCryptoStore()
        Get the CryptoStore interface to this token's objects.
      • equals

        boolean equals​(java.lang.Object object)
        Deep comparison operation. Use this, rather than ==, to determine whether two CryptoTokens are the same.
        Overrides:
        equals in class java.lang.Object
      • isPresent

        boolean isPresent()
        Determines whether this token is currently present. This could return false if the token is a smart card that was removed from its slot.
      • importPublicKey

        void importPublicKey​(java.security.PublicKey pubKey,
                             boolean permanent)
                      throws TokenException
        Throws:
        TokenException