Digital certificate for Spreadsheets has wrong format

Hi there,

I’m getting this error while trying to use the certificate constructed manually (C#) … I’m trying to avoid the popup that comes up in a solution 1 that is working,

The code that is working is here:

Stream excel_content;
MemoryStream cert_content;

        MemoryStream outStream = new MemoryStream();

using (Signature signature = new Signature(excel_content))
{
DigitalSignOptions options = new DigitalSignOptions(cert_content)
{
// certificate password
Password = “*****”,
// digital certificate details
Reason = “Approved”,
Contact = “John Smith”,
Location = “New York”,

                Appearance = new DigitalSignatureAppearance("rajoi", "Manager", "abcd@fdgs.com"),
                //                    
                AllPages = false,
                Width = 460,
                Height = 100,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Padding() { Bottom = 10, Right = 10 },

            };                // sign document to file
            SignResult signResult = signature.Sign(outStream, options);

            StreamWriter writer = new StreamWriter(outStream);

            //You have to rewind the MemoryStream before copying
            outStream.Seek(0, SeekOrigin.Begin);

            using (FileStream fs = new FileStream("signed.xlsx", FileMode.OpenOrCreate))
            {
                outStream.CopyTo(fs);
                fs.Flush();
            }
        }

The code that comes back with this error is below …

Error: GroupDocsSignatureException: Digital certificate for Spreadsheets has wrong format. Description: Certificate object can not be created from this Guid and password path is not set.

Stream excel_content;
MemoryStream cert_content;

MemoryStream outStream = new MemoryStream();

using (Signature signature = new Signature(excel_content))
{
DigitalSignOptions options = new DigitalSignOptions()
{
Signature = new DigitalSignature()
{
Certificate = new X509Certificate2(cert_content.ToArray(),
“*",
X509KeyStorageFlags.EphemeralKeySet),
},
// certificate password
// Password = "
”,
// digital certificate details
Reason = “Approved”,
Contact = “John Smith”,
Location = “New York”,

                Appearance = new DigitalSignatureAppearance("Rajoi", "Manager", "abcd@fdgs.com"),
                //                    
                AllPages = false,
                Width = 460,
                Height = 100,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Margin = new Padding() { Bottom = 10, Right = 10 },

            };                // sign document to file
            SignResult signResult = signature.Sign(outStream, options);

            StreamWriter writer = new StreamWriter(outStream);

            //You have to rewind the MemoryStream before copying
            outStream.Seek(0, SeekOrigin.Begin);

            using (FileStream fs = new FileStream("signed.xlsx", FileMode.OpenOrCreate))
            {
                outStream.CopyTo(fs);
                fs.Flush();
            }
        }

Thanks!

@rajoi

Could you please share more details? You share two code examples.

Example 1 is working for you but you are getting an exception? Could you please share the sample application alongside source file and the digital certificate?

Thanks for your reply … perhaps I can create a Hello World app to demo this … but the case is very straight forward. It would apply for any pfx certificate while trying to sign any Excel XLSX file

If I try to create the DigitalSignature by using an explicit constructor for X509Certificate2 I’m getting the exception.

Signature = new DigitalSignature()
{
Certificate = new X509Certificate2(
cert_content.ToArray(),
“”,
X509KeyStorageFlags.EphemeralKeySet),

}

The Exception is when I try to call sign method:

SignResult signResult = signature.Sign(outStream, options);

… and here is the exception itself.
“GroupDocsSignatureException: Digital certificate for Spreadsheets has wrong format. Description: Certificate object can not be created from this Guid and password path is not set.”

Thanks!

@rajoi
We are investigating this scenario. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SIGNATURENET-4486

We’ll notify you in case of any update or if any further details are required.
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi, @rajoi!

Thank you for your interest in GroupDocs.Signature.
We will fix this issue to support this property in the next June release 23.6.
Meantime, please be aware that this property is suppose to use for additional Digital signature properties like Location, etc.
To sign the document (Cells, Spreadsheets,Open Office spreadsheets) with the existing Digital Signature please use a little bit different API
You can find basic example here

or more advanced here

Feel free to ask any questions to help you move forward with the product!
Thank you!
CC @atir.tahir