We are using TMSCryptographyPack in the C++ Builder 10.2 Tokyo environment to integrate with KSeF in Poland.
At the end of our development work, we encountered a certain problem.
We have the following code for generating a signature using the TECCEncSign object:
UnicodeString dir, filename, cipher;
dir = ExtractFilePath(Application->ExeName);
// This line makes error - Public key incorrect, must be 88
// ecc->FromCertificateFile("C:\Users\Andrzej\Desktop\Drugi link\certyfikat\certyfikat.crt");
Memo1->Lines->Clear();
Memo1->Lines->LoadFromFile(dir + "\test.txt", TEncoding::UTF8);
ecc->FromPrivateKeyFile("C:\Users\Andrzej\Desktop\Drugi link\certyfikat\dcertyfikat.key");
cipher = ecc->Sign(Memo1->Lines->Text.Trim());
Memo1->Lines->Clear();
Memo1->Lines->LoadFromFile(dir + "\test.txt");
Memo1->Lines->Text = Memo1->Lines->Text + "/" + cipher;
The test.txt file contains only the following text:
ksef-test.mf.gov.pl/client-app/certificate/Nip/6571508893/6571508893/014AE117D068BBB5/UtQp9Gpc51y-u3xApZjIjgkpZ01js-J8KflSPW8WzIE
After executing the code, we obtain the full link with the signature:
ksef-test.mf.gov.pl/client-app/certificate/Nip/6571508893/6571508893/014AE117D068BBB5/UtQp9Gpc51y-u3xApZjIjgkpZ01js-J8KflSPW8WzIE/BCh4oVStUv91pPbKkI6Jv6j6A2qAfVQmnoUo00EqAlcNgSc5yXCPUoiVS0YZQdRCRQjD5GgGk9i1rOWjuP5o2Kk=
where the string
BCh4oVStUv91pPbKkI6Jv6j6A2qAfVQmnoUo00EqAlcNgSc5yXCPUoiVS0YZQdRCRQjD5GgGk9i1rOWjuP5o2Kk=
is the generated signature appended to the link. This string has 88 characters (87 without = char at the end). By the way, shouldn’t the = character be automatically removed for Base64URL by the ecc object? We tested the link both with and without this character and it still doesn’t work, so for now this is a secondary issue.
The ecc component on the form is configured as follows:
- ECCType: p256
- outputFormat: base64url
- NaCl: naclno
- Unicode: yesUni
The problem is that the generated link is invalid.
For comparison, we generate the same signature using the online tool:
We paste our key, select P‑256, SHA‑256, and PEM for the key. We paste exactly the same text as in test.txt and we obtain a Base64 string such as:
MEUCIQCnyGX8GuEk8Bt/mrLXvodpQJnDoh4/5fvIHC9l26+vqgIgAkIaWxIG1TdI0EMxje8tFuYEkCmOijTs3gQGDCV84Nk=
After converting it to Base64URL, we get:
MEUCIQCnyGX8GuEk8Bt_mrLXvodpQJnDoh4_5fvIHC9l26-vqgIgAkIaWxIG1TdI0EMxje8tFuYEkCmOijTs3gQGDCV84Nk
and then the link is valid
:
ksef-test.mf.gov.pl/client-app/certificate/Nip/6571508893/6571508893/014AE117D068BBB5/UtQp9Gpc51y-u3xApZjIjgkpZ01js-J8KflSPW8WzIE/MEUCIQCnyGX8GuEk8Bt_mrLXvodpQJnDoh4_5fvIHC9l26-vqgIgAkIaWxIG1TdI0EMxje8tFuYEkCmOijTs3gQGDCV84Nk
We would like to point out that the signature generated by TMS Crypto has 88 characters, while the one generated by the online tool has 96 characters (95 characters after Base64URL conversion, because the trailing = disappears).
We kindly ask for guidance on what might be wrong here. How can we achieve compatibility between TECCEncSign and the online tool?
Best regards,
Andrzej Gąsowski