qzind / qz-print

Archive for legacy qz-print versions (1.8, 1.9). See https://github.com/qzind/tray for modern versions.
Other
141 stars 101 forks source link

J# returns wrong signature #50

Closed tresf closed 9 years ago

tresf commented 9 years ago

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
tresf commented 9 years ago

Closed via https://github.com/qzind/qz-print/commit/700dbf7483a6e86ef72e5dfc833d8206a5896f6a, https://github.com/qzind/qz-print/commit/379e9eab5d45a6a03e4695dc1c5a0cdbd8eee634