Skip to main content

Hi !

I’m using java1.8 version and trying to get the Token using Java SDK , but we got the below exception.


Exception in thread “main” com.box.sdk.BoxAPIException: Error parsing PKCS private key for Box Developer Edition.



  • at com.box.sdk.BoxDeveloperEditionAPIConnection.decryptPrivateKey(BoxDeveloperEditionAPIConnection.java:568)*

  • at com.box.sdk.BoxDeveloperEditionAPIConnection.constructJWTAssertion(BoxDeveloperEditionAPIConnection.java:503)*

  • at com.box.sdk.BoxDeveloperEditionAPIConnection.authenticate(BoxDeveloperEditionAPIConnection.java:327)*

  • at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:182)*

  • at com.box.sdk.BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(BoxDeveloperEditionAPIConnection.java:216)*

  • at com.arondor.flower.tools.box.util.BoxAPI.setAPI(BoxAPI.java:54)*

  • at com.arondor.flower.tools.box.util.BoxAPI.getAPI(BoxAPI.java:33)*

  • at com.arondor.flower.tools.box.service.ServiceFolder.createBaseFolder(ServiceFolder.java:25)*

  • at com.arondor.flower.tools.box.Launcher.main(Launcher.java:18)*

    Caused by: org.bouncycastle.pkcs.PKCSException: unable to read encrypted data: javax.crypto.BadPaddingException: pad block corrupted

  • at org.bouncycastle.pkcs.PKCS8EncryptedPrivateKeyInfo.decryptPrivateKeyInfo(Unknown Source)*

  • at com.box.sdk.BoxDeveloperEditionAPIConnection.decryptPrivateKey(BoxDeveloperEditionAPIConnection.java:557)*

  • … 8 more*

    Caused by: java.io.IOException: javax.crypto.BadPaddingException: pad block corrupted

  • at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:128)*

  • at javax.crypto.CipherInputStream.read(CipherInputStream.java:246)*

  • at org.bouncycastle.util.io.Streams.pipeAll(Unknown Source)*

  • at org.bouncycastle.util.io.Streams.readAll(Unknown Source)*

  • … 10 more*

    Caused by: javax.crypto.BadPaddingException: pad block corrupted

  • at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$BufferedGenericBlockCipher.doFinal(Unknown Source)*

  • at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(Unknown Source)*

  • at javax.crypto.Cipher.doFinal(Cipher.java:2047)*

  • at javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:125)*

  • … 13 more*


Here is the code used to manage the connection


public class BoxAPI

{




  • private static final Logger LOGGER = Logger.getLogger(BoxAPI.class);*




  • private BatchConfiguration batchConfiguration = new BatchConfiguration();*




  • private String scope = null;*




  • private BoxDeveloperEditionAPIConnection api = null;*




  • private long counter;*




  • public BoxDeveloperEditionAPIConnection getAPI()*




  • {*




  •    if (api == null)*



  •        setAPI();*



  •    return api;*



  • }*




  • @PostConstruct*




  • private void setAPI()*




  • {*




  •    BoxConfig config = null;*



  •    try*



  •    {*



  •        Reader reader = new FileReader(batchConfiguration.getJsonPath());*



  •        config = BoxConfig.readFrom(reader);*



  •    }*



  •    catch (IOException e)*



  •    {*



  •        e.printStackTrace();*



  •    }*



  •    *



  •    if (config == null)*



  •        throw new NullPointerException("Config file error/n" + "filePath : " + batchConfiguration.getJsonPath());*



  •    api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(config);   *



  •    scope = "enterprise_" + config.getEnterpriseId();*



  •    if (api == null || config.getEnterpriseId() == null)*



  •        throw new NullPointerException("API OR SCOPE DATA NOT FOUND");*



  •    api.setRequestInterceptor(request -> {*



  •        // Do whatever counting or logging you want with the request*



  •        if (Long.MAX_VALUE == counter)*



  •            counter = 0L;*



  •        //LOGGER.info("BOX API COUNT (AFTER SERVICE STARTUP) : " + ++counter);*



  •        return null;*



  •    });*



  • }*




  • public String getScope()*




  • {*




  •    return scope;*



  • }*

    }




For information, I created a first application from the box developer interface, I have this problem even though I used key generation.

Additionally, one of my colleagues had created another application and using his json file for connection it works very well.

However, when I generate a new key for its alros application I again have the same problem as before


Please, help me

Hi,

the steps to handle the issue are described in README.md file.



Best,

Lukasz


Reply