The Problem
Getting this error when trying to authenticate with service account in Unity 6.0.58:
Unable to import PKCS#8 private key with the current runtime
Happens when calling RSA.ImportPkcs8PrivateKey() to sign JWT for OAuth token exchange.
Setup
-
Unity 6.0.58, Meta Quest (Android)
-
Trying to use service account JSON to generate OAuth tokens client-side
-
Need access tokens for Speech-to-Text V2 API calls
Questions
-
Does Unity’s Mono/.NET support PKCS#8 key import? Or do I need BouncyCastle?
-
Should I even do this client-side? Is server-side token generation the recommended pattern for Unity apps?
-
Can I just use API keys instead? Documentation shows API key option but I’m getting auth errors with that approach.
-
Any Unity samples/SDKs for Google Cloud authentication?
Code Context
Loading service account JSON → building JWT → signing with private key (fails here) → exchange for access token → use for API calls.
The RSA import methods available in .NET Standard 2.1+ don’t seem to exist in Unity 6’s runtime.
Platform: Android (Quest), .NET Standard 2.1, IL2CPP
Any guidance appreciated!