Class ProviderContext

java.lang.Object
org.jose4j.jca.ProviderContext

public class ProviderContext extends Object
Allows for the caller of various JOSE and JWT functionality to specify a particular Java Cryptography Architecture provider by name for various cryptographic operations as well as a SecureRandom source of randomness.

Use getSuppliedKeyProviderContext() to indicate the provider to be used for cryptographic operations directly involve the key supplied by the caller. Use getGeneralProviderContext() to indicate the provider to be used for other operations that do not directly involve the key supplied by the caller. Signing and verification are operations that use the supplied key as do key encryption and key agreement methods used to transmit or arrive at the content encryption key. Content encryption, however, is done with that content encryption key rather than the supplied key. So, other than when using direct (alg=dir) encryption, set the cipher provider name on the general provider to control the provider used in content encryption. For example, to specify the provider for an RSA signature when producing a JWS, create a new ProviderContext and set the name of the provider using ProviderContext.Context.setSignatureProvider(String) on the ProviderContext.Context obtained from calling getSuppliedKeyProviderContext(). To specify the provider for an HMAC when producing a JWS, set the name of the provider using ProviderContext.Context.setMacProvider(String) on the Context obtained from calling getSuppliedKeyProviderContext(). To specify the provider for decrypting a key with RSA when consuming a JWE, use ProviderContext.Context.setCipherProvider(String) on the Context obtained from getSuppliedKeyProviderContext(). To specify the provider for decrypting the content of the message, on the other hand, set the cipher provider on the Context obtained from getGeneralProviderContext().

A ProviderContext can be set on a JsonWebSignature or JsonWebEncryption as well as a JwtConsumer via the JwtConsumerBuilder.

See Also:
  • Constructor Details

    • ProviderContext

      public ProviderContext()
  • Method Details

    • getSuppliedKeyProviderContext

      public ProviderContext.Context getSuppliedKeyProviderContext()
      The Java Cryptography Architecture provider context to be used for operations that directly involve the key supplied by the caller.
      Returns:
      the Context object on which various provider preferences can be set
    • getGeneralProviderContext

      public ProviderContext.Context getGeneralProviderContext()
      The Java Cryptography Architecture provider context to be used for operations that do not directly involve the key supplied by the caller.
      Returns:
      the Context object on which various provider preferences can be set
    • getSecureRandom

      public SecureRandom getSecureRandom()
      Gets the secure random generator.
      Returns:
      The specific secure random generator if set, otherwise null for a default system one.
    • setSecureRandom

      public void setSecureRandom(SecureRandom secureRandom)
      Sets the secure random generator.
      Parameters:
      secureRandom - the SecureRandom to use or null for a default system one.