Go to solution
First-time Contributor


Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.

Source Error:

Line 32:         
Line 33:         static readonly BoxConfig boxConfig = new BoxConfig(CLIENT_ID, CLIENT_SECRET, ENTERPRISE_ID, JWT_PRIVATE_KEY, JWT_PRIVATE_KEY_PASSWORD, JWT_PUBLIC_KEY_ID);
Line 34:         public static readonly BoxJWTAuth BOX_JWT_HELPER = new BoxJWTAuth(boxConfig);Line 35: 
Line 36: 
Box Employee

Re: Box SDK MVc

Hi @umesh0801,


It sounds like the private key you're trying to use isn't in the right format or has some issues. How are you generating the private key?


- Jon

New Contributor

Re: Box SDK MVc

Hello @jcleblanc , I am also getting this exception. Do you think this might be happening because of the BOX SDK version? I have created a POC in my local machine in which I am generating the access token using JWT Auth by passing the private key in Boxconfig object in the below format and it is generating the access token. The Box SDK version that I am using in this POC project is 3.21.0, .net framework is 4.6


"-----BEGIN ENCRYPTED PRIVATE KEY-----\n**************************\n-----END ENCRYPTED PRIVATE KEY-----\n"


However, when I am integrating BOX in my existing MVC application to upload documents, it is throwing the casting error. The BOX SDK version used in my application is 2.15.6


PS- I am using the same private key in my MVC application.


Any help would be highly appreciated. Thanks