tftviking
tftviking
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
The same way with password as I used with path and then it worked. I have set permission for my app to get secrets in Key Vault
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
And with password
var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1,
Password = "swish"
};
var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1,
Password = "swish"
};
I get this
System.Security.Cryptography.CryptographicException: The specified network password is not correct. at System.Security.Cryptography.X509Certificates.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate) at SwishApi.PayoutClient.MakePayoutRequest(String payoutTo, String personalNumber, Decimal amount, String message, String instructionUUID, String signingCertificateSerialNumber, ClientCertificate signingCertificate)
System.Security.Cryptography.CryptographicException: The specified network password is not correct. at System.Security.Cryptography.X509Certificates.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate) at SwishApi.PayoutClient.MakePayoutRequest(String payoutTo, String personalNumber, Decimal amount, String message, String instructionUUID, String signingCertificateSerialNumber, ClientCertificate signingCertificate)
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
But next problem. When I running from local it works now getting from Key Vault and do the memorystream without enter password.
var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1
};
var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1
};
When uploaded on Azure with no password I get
System.Security.Cryptography.CryptographicException: The system cannot find the file specified. at System.Security.Cryptography.X509Certificates.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate) at SwishApi.PayoutClient.MakePayoutRequest(String payoutTo, String personalNumber, Decimal amount, String message, String instructionUUID, String signingCertificateSerialNumber, ClientCertificate signingCertificate)
System.Security.Cryptography.CryptographicException: The system cannot find the file specified. at System.Security.Cryptography.X509Certificates.CertificatePal.FilterPFXStore(ReadOnlySpan`1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlobOrFile(ReadOnlySpan`1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate) at SwishApi.PayoutClient.MakePayoutRequest(String payoutTo, String personalNumber, Decimal amount, String message, String instructionUUID, String signingCertificateSerialNumber, ClientCertificate signingCertificate)
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Yes :
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
But this small service im building now is for a friend that buys and sell video games and other collectables like trading cards etc. When he buying from private individuals its easier to swish from the companys account rather than transfer money and swish from personal.
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Or you generate the certs in the swish panel but to get access
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Its the customers certs. to use my service. When you request cert for Payout from your bank they ask if you have a solution to use the cert and for what purpose you want the cert.
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Take a look at utbetalningar.nu
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
There are services that almost do what I want already, so can't see that it should be any problems.
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Are you Swedish?
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
For companies to make payouts
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Okey, the example was with filepath but i got access denied so i thought better to use Key Vault since im planning building a Saas solution for this since Swish it self dosent offer the service public. Just API
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Yes, i'm newbie. Im taking a 8 month course now as Developer
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
// Ladda ner certifikaten som secrets
var secretBundle1 = await keyVaultClient.GetSecretAsync("TestCertificate");
var secretBundle2 = await keyVaultClient.GetSecretAsync("TestSigningCertificate");

// Skapa MemoryStream-objekt från secrets
using var certificateStream1 = new MemoryStream(Convert.FromBase64String(secretBundle1.Value.Value));
using var certificateStream2 = new MemoryStream(Convert.FromBase64String(secretBundle2.Value.Value));

var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1
};

var clientCertificate2 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream2
};
// Ladda ner certifikaten som secrets
var secretBundle1 = await keyVaultClient.GetSecretAsync("TestCertificate");
var secretBundle2 = await keyVaultClient.GetSecretAsync("TestSigningCertificate");

// Skapa MemoryStream-objekt från secrets
using var certificateStream1 = new MemoryStream(Convert.FromBase64String(secretBundle1.Value.Value));
using var certificateStream2 = new MemoryStream(Convert.FromBase64String(secretBundle2.Value.Value));

var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream1
};

var clientCertificate2 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = certificateStream2
};
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
First of all i loaded the public cert, not the secret.
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Got it to work...
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Anyway with or without that I get System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=SwishApi StackTrace: at SwishApi.Models.PayoutRequestEnvelope.buildSignature(ClientCertificate signingCertificate)
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
xD
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
Stil not working, I can see in the breakpoints that I get the cert.
65 replies
CC#
Created by tftviking on 10/3/2023 in #help
❔ Load Certificate from Azure Key Vault as memorystream
var certificateOptions1 = new DownloadCertificateOptions("TestCertificate");
var response1 = await keyVaultClient.DownloadCertificateAsync(certificateOptions1);
var certificate1 = response1.Value;

var certificateOptions2 = new DownloadCertificateOptions("TestSigningCertificate");
var response2 = await keyVaultClient.DownloadCertificateAsync(certificateOptions2);
var certificate2 = response2.Value;

using var certificateStream1 = new MemoryStream(certificate1.RawData);
using var certificateStream2 = new MemoryStream(certificate2.RawData);

// Omvandla MemoryStream till byte array
byte[] certificateData1 = certificateStream1.ToArray();
byte[] certificateData2 = certificateStream2.ToArray();

// Skapa X509Certificate2-objekt
var x509Certificate1 = new X509Certificate2(certificateData1);
var x509Certificate2 = new X509Certificate2(certificateData2);

var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = new MemoryStream(x509Certificate1.Export(X509ContentType.Pkcs12, "swish")),
Password = "swish",
UseMachineKeySet = true
};

var clientCertificate2 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = new MemoryStream(x509Certificate2.Export(X509ContentType.Pkcs12, "swish")),
Password = "swish",
UseMachineKeySet = true
};
var certificateOptions1 = new DownloadCertificateOptions("TestCertificate");
var response1 = await keyVaultClient.DownloadCertificateAsync(certificateOptions1);
var certificate1 = response1.Value;

var certificateOptions2 = new DownloadCertificateOptions("TestSigningCertificate");
var response2 = await keyVaultClient.DownloadCertificateAsync(certificateOptions2);
var certificate2 = response2.Value;

using var certificateStream1 = new MemoryStream(certificate1.RawData);
using var certificateStream2 = new MemoryStream(certificate2.RawData);

// Omvandla MemoryStream till byte array
byte[] certificateData1 = certificateStream1.ToArray();
byte[] certificateData2 = certificateStream2.ToArray();

// Skapa X509Certificate2-objekt
var x509Certificate1 = new X509Certificate2(certificateData1);
var x509Certificate2 = new X509Certificate2(certificateData2);

var clientCertificate1 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = new MemoryStream(x509Certificate1.Export(X509ContentType.Pkcs12, "swish")),
Password = "swish",
UseMachineKeySet = true
};

var clientCertificate2 = new SwishApi.Models.ClientCertificate()
{
CertificateAsStream = new MemoryStream(x509Certificate2.Export(X509ContentType.Pkcs12, "swish")),
Password = "swish",
UseMachineKeySet = true
};
65 replies