JWT Authentication in JAVA throwing error as decryptPrivateKeyInfo(Unknown Source)
I am trying to upload the files to BOX using a service account, with JWT authentication.
I have set up a custom APP in Box, and is authorized by Admin. The Appication access is set to "Application", and application scope includes "Read/write all files/fodlers in Box" and "Mange Users". The Advanced Features is to "Generate User Access Token"
I am able to access the files using a Box developer token from this Box App.
But while using JWT authentication I am getting the error as at line
BoxDeveloperEditionAPIConnection client = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache);
Exception in thread "main" java.lang.NoSuchFieldError: id_hmacWithSHA3_224
at org.bouncycastle.openssl.jcajce.PEMUtilities.(Unknown Source)
at org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8DecryptorProviderBuilder$1.get(Unknown Source)
at org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo.decryptPrivateKeyInfo(Unknown Source)
at com.box.sdk.BoxDeveloperEditionAPIConnection.decryptPrivateKey(BoxDeveloperEditionAPIConnection.java:504)
at com.box.sdk.BoxDeveloperEditionAPIConnection.constructJWTAssertion(BoxDeveloperEditionAPIConnection.java:450)
at com.box.sdk.BoxDeveloperEditionAPIConnection.constructJWTAssertion(BoxDeveloperEditionAPIConnection.java:431)
at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:320)
at com.box.sdk.BoxDeveloperEditionAPIConnection.tryRestoreUsingAccessTokenCache(BoxDeveloperEditionAPIConnection.java:419)
at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:199)
at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:226)
at com.acc.ecm.cap.box.FolderIter_JWT.main(FolderIter_JWT.java:114)
I am following below Box article, and have installed JCE as instructed(We are located in US). We have JRE 1.8 installed and am using JAVA for development
https://github.com/box/box-java-sdk
Below is the code I am following:
// Read config file into Box Config object
Reader reader = new FileReader("F:\\BOX_CONNECTOR\\config\\48245_f10g2l6t_config.json");
BoxConfig boxConfig = BoxConfig.readFrom(reader);
// Set cache info
int MAX_CACHE_ENTRIES = 100;
IAccessTokenCache accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES);
BoxDeveloperEditionAPIConnection client =
BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache);
// PERFORM ACTIONS WITH CLIENT
String filePath = "E:\\emltopdf-app-strap03.txt";
String fileName = "TESTJWT";
String folderId = "***number removed for privacy***99";
// Select Box folder
BoxFolder folder = new BoxFolder(client, folderId);
// Upload file
FileInputStream stream = new FileInputStream(filePath);
BoxFile.Info newFileInfo = folder.uploadFile(stream, fileName);
stream.close();
-
Hey Ashna,
I'm not much aware of java but one thing is sure that you are getting this error because of the private key,public key combination. I think you are downloading the default public key offered by box. This public key which you download actually contains the private key in an encrypted format and that is why its not able to communicate properly. I would recommend to create your own private and public key to resolve this error.
Please sign in to leave a comment.
Comments
1 comment