oracle / oci-dotnet-sdk

Oracle Cloud Infrastructure SDK for .NET
https://cloud.oracle.com/cloud-infrastructure
Other
53 stars 20 forks source link

How to Authenticate PrivateKey file data from DB instead on Physical Private key by passing Path. #236

Open BPKReddy opened 3 months ago

BPKReddy commented 3 months ago

I'm trying to connect "OCI Object Storage" from .Net Application. Currently able to connect with providing PrivateKey file path and "PrivateKey File" available in Physical path. All other values are coming from the Database.

Due to security reasons, I cannot have a physical "PrivateKey" file on the server. Need to maintain PrivateKey file content also in the Database and Authenticate. I'm fine with storing PrivateKey file content as a string in DB or storing "PrivateKey file" as BLOB. Then read "PrivateKey" from DB and build SimpleAuthenticationDetailsProvider object.

please suggest me how can I read "PrivateKey file content" from a Variable or File object.

var provider = new SimpleAuthenticationDetailsProvider { TenantId = "ocid1.tenancy", UserId = "ocid1.user", Fingerprint = "Fingerprint Value", Region = Region.FromRegionId("us-ashburn-5"), PrivateKeySupplier = new FilePrivateKeySupplier("C:\Pavan\PrivateKey\customer-3_2024-03-19T07_58_29.636Z.pem", new SecureString()), };

nghianguyen09 commented 3 months ago

@BPKReddy

you just simply pass the content of private key file as string as sample code below

string privateKey = "private key content from DB";
var provider = new SimpleAuthenticationDetailsProvider
{
  //....
  PrivateKeySupplier = new PrivateKeySupplier(privateKey)
}

Hope it helps.