androidencryptionjwtjwenimbus-jose-jwt

Cannot resolve symbol 'encrypt' in nimbus-jose-jwt library


I am trying to generate an encrypted JWT in Android using 'nimbus-jose-jwt' library. But when I call the method 'encrypt()' of library, I get the error 'Cannot resolve symbol 'encrypt', even though the source code of library has the method 'encrypt()' for the object I specified.

This is my code:

 public class EncryptedJWTGenerator {
   
 public EncryptedJWTGenerator() throws NoSuchAlgorithmException, JOSEException {
    }

    JWEAlgorithm alg = JWEAlgorithm.RSA_OAEP_256;
    EncryptionMethod enc = EncryptionMethod.A128CBC_HS256;

    KeyPairGenerator rsaGen = KeyPairGenerator.getInstance("RSA");
    //rsaGen.initialize(2048);
    KeyPair rsaKeyPair = rsaGen.generateKeyPair();
    RSAPublicKey rsaPublicKey = (RSAPublicKey)rsaKeyPair.getPublic();


    // Generate the preset Content Encryption (CEK) key
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");

    SecretKey cek = keyGenerator.generateKey();

    // Encrypt the JWE with the RSA public key + specified AES CEK
    JWEObject jweObject = new JWEObject(new JWEHeader(alg, enc), new Payload("Hello, world!"));

    jweObject.encrypt(new RSAEncrypter(rsaPublicKey, cek)); //**ERROR IN THIS LINE**

    String jweString = jweObject.serialize();
    
}

I have been trying to resolve this for hours, but not successful yet. Please suggest a solution.


Solution

  • There are two bugs in the code:

    With these changes the code works on my machine (API28/P).