Skip to main content
New Participant
Apr 9, 2024 4:21 PM UTC

PEMParser return null and the boxPrivateKey is base64

Security.addProvider(new BouncyCastleProvider());

PEMParser pemParser = new PEMParser(
  new StringReader(config.boxAppSettings.appAuth.privateKey)
);
Object keyPair = pemParser.readObject();
pemParser.close();

the keyPair return null?

    1 reply

    rbarbosa Box
    Developer Advocate
    Apr 10, 2024 2:01 PM UTC

    Hi @moaldini , welcome to the forum!

    If you got the private key from Box while setting up the JWT application, please note the private key is encrypted.

    You can extract it using something like:

    openssl rsa -in your_encrypted_private-key-file.pem -out decrypted-private-key-file.pem  -passin pass:your-pass-phrase
    
    

    Most likely Bouncy Caste will also have methods to decrypt a private key.

    Let us know if this helps

    Translate