Class KeyUsageExtension

  • All Implemented Interfaces:
    java.io.Serializable, CertAttrSet

    public class KeyUsageExtension
    extends Extension
    implements CertAttrSet
    Represent the Key Usage Extension.

    This extension, if present, defines the purpose (e.g., encipherment, signature, certificate signing) of the key contained in the certificate. The usage restriction might be employed when a multipurpose key is to be restricted (e.g., when an RSA key should be used only for signing or only for key encipherment).

    Version:
    1.9
    Author:
    Amit Kapoor, Hemma Prafullchandra
    See Also:
    Extension, CertAttrSet, Serialized Form
    • Constructor Detail

      • KeyUsageExtension

        public KeyUsageExtension​(boolean critical,
                                 byte[] bitString)
                          throws java.io.IOException
        Create a KeyUsageExtension with the passed bit settings. The criticality is set to true.
        Parameters:
        bitString - the bits to be set for the extension.
        Throws:
        java.io.IOException
      • KeyUsageExtension

        public KeyUsageExtension​(byte[] bitString)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • KeyUsageExtension

        public KeyUsageExtension​(boolean critical,
                                 boolean[] bitString)
                          throws java.io.IOException
        Create a KeyUsageExtension with the passed bit settings. The criticality is set to true.
        Parameters:
        bitString - the bits to be set for the extension.
        Throws:
        java.io.IOException
      • KeyUsageExtension

        public KeyUsageExtension​(boolean[] bitString)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • KeyUsageExtension

        public KeyUsageExtension​(BitArray bitString)
                          throws java.io.IOException
        Create a KeyUsageExtension with the passed bit settings. The criticality is set to true.
        Parameters:
        bitString - the bits to be set for the extension.
        Throws:
        java.io.IOException
      • KeyUsageExtension

        public KeyUsageExtension​(java.lang.Boolean critical,
                                 java.lang.Object value)
                          throws java.io.IOException
        Create the extension from the passed DER encoded value of the same.
        Parameters:
        critical - true if the extension is to be treated as critical.
        value - Array of DER encoded bytes of the actual value.
        Throws:
        java.io.IOException - on error.
      • KeyUsageExtension

        public KeyUsageExtension()
        Create a default key usage.
    • Method Detail

      • set

        public void set​(java.lang.String name,
                        java.lang.Object obj)
                 throws java.io.IOException
        Set the attribute value.
        Specified by:
        set in interface CertAttrSet
        Parameters:
        name - the name of the attribute (e.g. "x509.info.key")
        obj - the attribute object.
        Throws:
        java.io.IOException - on other errors.
      • get

        public java.lang.Object get​(java.lang.String name)
                             throws java.io.IOException
        Get the attribute value.
        Specified by:
        get in interface CertAttrSet
        Parameters:
        name - the name of the attribute to return.
        Throws:
        java.io.IOException - on other errors.
      • delete

        public void delete​(java.lang.String name)
                    throws java.io.IOException
        Delete the attribute value.
        Specified by:
        delete in interface CertAttrSet
        Parameters:
        name - the name of the attribute to delete.
        Throws:
        java.io.IOException - on other errors.
      • toString

        public java.lang.String toString()
        Returns a printable representation of the KeyUsage.
        Specified by:
        toString in interface CertAttrSet
        Overrides:
        toString in class Extension
        Returns:
        value of this certificate attribute in printable form.
      • decode

        public void decode​(java.io.InputStream in)
                    throws java.io.IOException
        Decode the extension from the InputStream.
        Specified by:
        decode in interface CertAttrSet
        Parameters:
        in - the InputStream to unmarshal the contents from.
        Throws:
        java.io.IOException - on decoding or validity errors.
      • encode

        public void encode​(java.io.OutputStream out)
                    throws java.io.IOException
        Write the extension to the DerOutputStream.
        Specified by:
        encode in interface CertAttrSet
        Parameters:
        out - the DerOutputStream to write the extension to.
        Throws:
        java.io.IOException - on encoding errors.
      • getAttributeNames

        public java.util.Enumeration<java.lang.String> getAttributeNames()
        Return an enumeration of names of attributes existing within this attribute.
        Specified by:
        getAttributeNames in interface CertAttrSet
        Returns:
        an enumeration of the attribute names.
      • getBits

        public boolean[] getBits()
      • getName

        public java.lang.String getName()
        Return the name of this attribute.
        Specified by:
        getName in interface CertAttrSet
        Returns:
        the name of this CertAttrSet.