microsoft / service-fabric-issues

This repo is for the reporting of issues found with Azure Service Fabric.
168 stars 21 forks source link

Using EncryptionUtility to Encrypt/Decrypt Text #1680

Closed temelj closed 4 years ago

temelj commented 4 years ago

I am trying to encrypt/decrypt text given a cert thumbprint in the my service fabric app startup.

var encrypt = EncryptionUtility.EncryptText("testing123", "eb f6 36 ba 23 10 d3 3c 82 69 a1 7c 08 60 ad c0 fb 2e 60 bf", "My");

var decrypted = EncryptionUtility.DecryptText(encrypt, StoreLocation.LocalMachine);

I have an equivalent PowerShell script that actually works

# Encrypt Text
$thumbprint='eb f6 36 ba 23 10 d3 3c 82 69 a1 7c 08 60 ad c0 fb 2e 60 bf'
$encryptedText = Invoke-ServiceFabricEncryptText -Text 'test123' -CertThumbprint $thumbprint -CertStore -StoreLocation LocalMachine -StoreName My

# Decrypt Text
Invoke-ServiceFabricDecryptText -CipherText $encryptedText -StoreLocation "LocalMachine"

Current Behavior

DecryptText fails with: Cannot find the certificate and private key to use for decryption. (Exception from HRESULT: 0x8009200C)

Stack Trace:

   at System.Fabric.Security.EncryptionUtility.DecryptText(String textToDecrypt, StoreLocation storeLocation)
   at My.Api.Startup.ConfigureServices(IServiceCollection services) in D:\temelj\My.FabricApp\src\My.Api\Startup.cs:line 97

Service Fabric Runtime and SDK Version :

Runtime: 7.0.466.9590 SDK: 4.0.466.9590 .NET Core 3.1

temelj commented 4 years ago

apologies for raising it here - see https://github.com/microsoft/service-fabric/issues/949