When using UTF8Encoding the signature won't validate. This seems to be fixed by switching the code to use ASCIIEncoding. If this fixes the issue, it will need to be corrected in our C# sample.
module sample
open System
open System.Security.Cryptography
open System.Security.Cryptography.X509Certificates
open System.IO
open System.Text
let request = "test data"
let cert = new X509Certificate2("converted-private-key.pfx", String.Empty)
let sha1 = new SHA1CryptoServiceProvider()
let csp = cert.PrivateKey :?> RSACryptoServiceProvider
let encoder = new ASCIIEncoding()
// ^------------- HERE
let data = encoder.GetBytes(request)
let binaryData = csp.SignData(data, sha1)
let output = Convert.ToBase64String(binaryData)
Console.WriteLine output
When using
UTF8Encoding
the signature won't validate. This seems to be fixed by switching the code to useASCIIEncoding
. If this fixes the issue, it will need to be corrected in our C# sample.