The java.security package provides classes and interfaces for implementing security-related operations in Java. It includes APIs for cryptography, key management, digital signatures, message digests, security providers, and other security mechanisms.
In this chapter, you will learn about the java.security package, its commonly used classes and interfaces, and how to import and use the package in Java programs.
The java.security package is a standard Java package that provides classes and interfaces for security and cryptographic operations. It includes APIs for generating and managing keys, creating digital signatures, calculating message digests, and accessing security-related services.
The package also provides classes for working with security providers and cryptographic algorithms.
The entire java.security package can be imported using the following syntax:
import java.security.*;
A specific class from the package can also be imported individually:
import java.security.MessageDigest;
The wildcard import makes the accessible classes and interfaces in the java.security package available in the program, while importing a specific class imports only that class.
All the classes which are related for management of security related concerns in the java program are provided under this package. The various classes are discussed below:
| Class | Description |
|---|---|
| AccessControlContext | Various decisions related to the access provision of system resources is taken by this class. The class is declared as: public final class AccessControlContext extends Object The class methods are inherited from the Object class. |
| AccessController | Various decisions related to the access provision of system resources is taken by this class. The class is declared as: public final class AccessController extends Object The class methods are inherited from the Object class. |
| AlgorithmParameterGenerator | The class controls operations related to formation of various parameters to be used in an algorithm. The class is declared as: public class AlgorithmParameterGenerator extends Object The class methods are inherited from the Object class. |
| AlgorithmParameterGeneratorSpi | The class is used for the generation of SPI to be used by the AlgorithmParameterGenerator class. The class is declared as: public abstract class AlgorithmParameterGeneratorSpi extends Object The class methods are inherited from the Object class. |
| AlgorithmParameters | The class is used for the representation of various parameters which are opaque. The class is declared as: public class AlgorithmParameters extends Object The class methods are inherited from the Object class. |
| AlgorithmParametersSpi | The class is used for generation of SPI to be used by the AlgorithmParameters class. The class is declared as: public abstract class AlgorithmParametersSpi extends Object The class methods are inherited from the Object class. |
| AllPermission | The class instances reflect that all other permissions are provided to the entity. The class is declared as: public final class AllPermission extends Permission The class methods are inherited from the Permission class. |
| AuthProvider | The class defines the permissions related to authentication. The class is declared as: public final class AuthProvider extends Provider The class methods are inherited from the Provider class. |
| BasicPermission | It is the parents class for all the permission classes. The class is declared as: public abstract class BasicPermission extends Permission implements Serializable The class methods are inherited from the Permission class. |
| CodeSigner | The instances of the class wrap up information about the class signer. The class is declared as: public final class CodeSigner extends Object implements Serializable The class methods are inherited from the Object class. |
| CodeSource | The class instances wraps up various entities which are used to check the authenticity of a connection. The class is declared as: public class CodeSource extends Object implements Serializable The class methods are inherited from the Object class. |
| DigestInputStream | It is a class which is specially used for the message updating using going bits. The class is declared as: public class DigestInputStream extends FilterInputStream The class methods are inherited from the FilterInputStream class |
| DigestOutputStream | It is a class which is specially used for the message updating using going bits. The class is declared as: public class DigestOutputStream extends FilterOutputStream The class methods are inherited from the FilterOutputStream class |
| GuardedObject | The instances of the class are used to regulate the access to other objects. The class is declared as: public class GuardedObject extends Object implements Serializable The class methods are inherited from the Object class |
| KeyFactory | The class is used for the conversion of keys into its respective specifications and vice versa. The class is declared as: public class KeyFactory extends Object The class methods are inherited from the Object class |
| KeyFactorySpi | The class instances define SPI for the KeyFactory class. The class is declared as: public abstract class KeyFactorySpi extends Object The class methods are inherited from the Object class |
| KeyPair | The class is basically is a holder for the key values. The class is declared as: public final class KeyPair extends Object implements Serializable The class methods are inherited from the Object class |
| KeyPairGenerator | The class instances are used for the generation of various keys with the required access specifiers. The class is declared as: public abstract class KeyPairGenerator extends KeyPairGeneratorSpi The class methods are inherited from the KeyPairGeneratorSpi class |
| KeyPairGeneratorSpi | The class instances represent the SPI for the KeyPairGenerator class. The class is declared as: public abstract class KeyPairGeneratorSpi extends Object The class methods are inherited from the Object class |
| KeyRep | The class instances represent the various key values. The class is declared as: public class KeyRep extends Object implements Serializable The class methods are inherited from the Object class |
| KeyStore | The class is used as a store house for various types of keys. The class is declared as: public class KeyStore extends Object The class methods are inherited from the Object class |
| KeyStore.Builder | The class is used by the KeyStore class. The class is declared as: public abstract static class KeyStore.Builder extends Object The class methods are inherited from the Object class |
| KeyStore.CallbackHandlerProtection | The class is a wrapper type for the CallbackHandler. The class is declared as: public static class KeyStore.CallbackHandlerProtection extends Object implements KeyStore.ProtectionParameter The class methods are inherited from the Object class |
| KeyStore.PasswordProtection | The class instances support authentication related security. The class is declared as: public static class KeyStore.PasswordProtection extends Object implements KeyStore.ProtectionParameter, Destroyable The class methods are inherited from the Object class |
| KeyStore.PrivateKeyEntry | The class instances represent the private key. The class is declared as: public static final class KeyStore.PrivateKeyEntry extends Object implements KeyStore.Entry The class methods are inherited from the Object class |
| KeyStore.SecretKeyEntry | The class instances represent the security key. The class is declared as: public static final class KeyStore.SecretKeyEntry extends Object implements KeyStore.Entry The class methods are inherited from the Object class |
| KeyStore.TrustedCertificateEntry | The class instances represent the certificate entry. The class is declared as: public static final class KeyStore.TrustedCertificateEntry extends Object implements KeyStore.Entry The class methods are inherited from the Object class |
| MessageDigest | The class provides the programs with MessageDigest facility. The class is declared as: public abstract class MessageDigest extends MessageDigestSpi The class methods are inherited from the MessageDigestSpi class |
| Permission | The class is meant to handle concerns related to accessing of system resources. The class is declared as: public abstract class Permission extends Object implements Guard, Serializable The class methods are inherited from the Object class |
| PermissionCollection | It is an abstract class. The class represents a collection of permission objects. The class is declared as: public abstract class PermissionCollection extends Object implements Serializable The class methods are inherited from the Object class |
| Policy | The instances of the class determine whether the code being executed by the JVM has required permission to access the security policies. The class is declared as: public abstract class Policy extends Object The class methods are inherited from the Object clas |
| ProtectionDomain | All the characteristics of a domain are wrapped in the class. The class is declared as: public class ProtectionDomain extends Object The class methods are inherited from the Object class |
| Provider | The class instance acts as a JDBC API provider. The class is declared as: public abstract class Provider extends Properties The class methods are inherited from the Properties class |
| Provider.Service | The class instances provide various relevant information regarding the security services. The class is declared as: public static class Provider.Service extends Object The class methods are inherited from the Object class |
| SecureRandom | A random number generator is provided by this class. The class is declared as: public class SecureRandom extends Random The class methods are inherited from the Random class |
| Security | All the security related concerns and the specific properties are provided by this class. The class is declared as: public final class Security extends Object The class methods are inherited from the Object class |
| SecurityPermission | All the security related permissions are provided by this class. The class is declared as: public final class SecurityPermission extends BasicPermission The class methods are inherited from the BasicPermission class |
| Signature | Signal related algorithms are provided by the class instances. The class is declared as: public abstract class Signature extends SignatureSpi The class methods are inherited from the SignatureSpi class |
| SignatureSpi | The class instances create SPI for the Signature class. The class is declared as: public abstract class SignatureSpi extends Object The class methods are inherited from the Object class |
| SignedObject | The class created various runtime objects. The authenticity of the objects created is strict. The class is declared as: public final class SignedObject extends Object implements Serializable The class methods are inherited from the Object class |
| Timestamp | related information is reflected by the class. The class is declared as: public final class Timestamp extends Object implements Serializable The class methods are inherited from the Object class |
| UnresolvedPermission | The class instances hold various permission concerns which were left unresolved. The class is declared as: public final class UnresolvedPermission extends Permission implements Serializable The class methods are inherited from the Permission class |
| URIParameter | The class contains the parameter which points to an URL address. The class is declared as: public class URIParameter extends Object implements Policy.Parameters, Configuration.Parameters The class methods are inherited from the Object class |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India