com.nimbusds.jose.crypto
Class RSAEncrypter

java.lang.Object
  extended by com.nimbusds.jose.crypto.RSAEncrypter
All Implemented Interfaces:
JWEAlgorithmProvider, JWEEncrypter

public class RSAEncrypter
extends java.lang.Object
implements JWEEncrypter

This class is not fully tested and is provided for documentation and development purposes only. See Issue #11 RSA encrypter.

Version:
$version$ (2013-02-21)
Author:
David Ortiz, Vladimir Dzhuvinov

Field Summary
static java.util.Set<JWEAlgorithm> SUPPORTED_ALGORITHMS
           
static java.util.Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS
           
 
Constructor Summary
RSAEncrypter(java.security.interfaces.RSAPublicKey pubKey)
          Creates a new RSA encrypter.
 
Method Summary
protected  byte[] aesgcmDecrypt(javax.crypto.spec.IvParameterSpec ivParamSpec, javax.crypto.SecretKey secretKey, byte[] cipherText)
           
protected  byte[] aesgcmEncrypt(javax.crypto.spec.IvParameterSpec ivParamSpec, javax.crypto.SecretKey secretKey, byte[] cipherText)
           
 JWECryptoParts encrypt(ReadOnlyJWEHeader readOnlyJWEHeader, byte[] bytes)
          Encrypts the specified clear text of a JWE object.
protected static javax.crypto.SecretKey generateAESCMK(int keyLength)
          Generates an AES Content Master Key (CMK) of the specified length.
protected  byte[] generateAESGCMIV()
          Generates a random 96 bit (12 byte) Initialisation Vector(IV) for use in AES-GCM encryption.
protected  int keyLengthForMethod(EncryptionMethod method)
          Gets the Content Master Key (CMK) length for the specified encryption method.
 java.util.Set<JWEAlgorithm> supportedAlgorithms()
          Returns the names of the supported JWE algorithms.
 java.util.Set<EncryptionMethod> supportedEncryptionMethods()
          Returns the names of the supported encryption methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.nimbusds.jose.JWEAlgorithmProvider
supportedAlgorithms, supportedEncryptionMethods
 

Field Detail

SUPPORTED_ALGORITHMS

public static final java.util.Set<JWEAlgorithm> SUPPORTED_ALGORITHMS

SUPPORTED_ENCRYPTION_METHODS

public static final java.util.Set<EncryptionMethod> SUPPORTED_ENCRYPTION_METHODS
Constructor Detail

RSAEncrypter

public RSAEncrypter(java.security.interfaces.RSAPublicKey pubKey)
Creates a new RSA encrypter.

Parameters:
pubKey - The public RSA key. Must not be null.
Method Detail

encrypt

public JWECryptoParts encrypt(ReadOnlyJWEHeader readOnlyJWEHeader,
                              byte[] bytes)
                       throws JOSEException
Description copied from interface: JWEEncrypter
Encrypts the specified clear text of a JWE object.

Specified by:
encrypt in interface JWEEncrypter
Parameters:
readOnlyJWEHeader - The JSON Web Encryption (JWE) header. Must specify a supported JWE algorithm and must not be null.
bytes - The clear text to encrypt. Must not be null.
Returns:
The resulting JWE crypto parts.
Throws:
JOSEException - If the JWE algorithm is not supported or if encryption failed for some other reason.

generateAESCMK

protected static javax.crypto.SecretKey generateAESCMK(int keyLength)
                                                throws java.security.NoSuchAlgorithmException
Generates an AES Content Master Key (CMK) of the specified length.

Parameters:
keyLength - The key length, in bits.
Returns:
The AES CMK.
Throws:
java.security.NoSuchAlgorithmException - If AES key generation is not supported.

generateAESGCMIV

protected byte[] generateAESGCMIV()
Generates a random 96 bit (12 byte) Initialisation Vector(IV) for use in AES-GCM encryption.

See http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-08#section-4.9

Returns:
The random 96 bit IV.

supportedAlgorithms

public java.util.Set<JWEAlgorithm> supportedAlgorithms()
Description copied from interface: JWEAlgorithmProvider
Returns the names of the supported JWE algorithms. These correspond to the alg JWE header parameter.

Specified by:
supportedAlgorithms in interface JWEAlgorithmProvider
Returns:
The supported JWE algorithms, empty set if none.

supportedEncryptionMethods

public java.util.Set<EncryptionMethod> supportedEncryptionMethods()
Description copied from interface: JWEAlgorithmProvider
Returns the names of the supported encryption methods. These correspond to the enc JWE header parameter.

Specified by:
supportedEncryptionMethods in interface JWEAlgorithmProvider
Returns:
The supported encryption methods, empty set if none.

keyLengthForMethod

protected int keyLengthForMethod(EncryptionMethod method)
Gets the Content Master Key (CMK) length for the specified encryption method.

Parameters:
method - The encryption method. Must be supported by this RSA provider. Must not be null.
Returns:
The CMK length, in bits.

aesgcmDecrypt

protected byte[] aesgcmDecrypt(javax.crypto.spec.IvParameterSpec ivParamSpec,
                               javax.crypto.SecretKey secretKey,
                               byte[] cipherText)
                        throws JOSEException
Throws:
JOSEException

aesgcmEncrypt

protected byte[] aesgcmEncrypt(javax.crypto.spec.IvParameterSpec ivParamSpec,
                               javax.crypto.SecretKey secretKey,
                               byte[] cipherText)
                        throws JOSEException
Throws:
JOSEException


Copyright © 2013 NimbusDS. All Rights Reserved.