Archived Forum Post

Index of archived forum posts

Question:

I can sign a file with p7s on one computer, but a new computer doesn't let me

Mar 04 '16 at 11:32

I have this code that signs a file and then outputs a detached signature file. The code works perfectly on one machine, but I go to a newer machine and it does not work. I have tried all versions of chilkat and it won't generate the signature file, but the code compiles and has no issues. I copied the code below. Please HELP!

//in Nuget ChilkatDotNet4 void Main() { Chilkat.Crypt crypt = new Chilkat.Crypt();

crypt.UnlockComponent("UnlockCode");

// Read the PDF
System.IO.FileInfo fInfo = new System.IO.FileInfo(@"D:\AttidoMobile\manifest.json");
System.IO.BinaryReader br = new System.IO.BinaryReader(
    System.IO.File.OpenRead(@"D:\AttidoMobile\manifest.json"));
byte [] pdfBytes = br.ReadBytes((int)fInfo.Length);
br.Close();

// Indicate which digital certificate is to be used.
// This certificate must have the private key installed on the system.
Chilkat.Cert cert = new Chilkat.Cert();
// Replace this line with your own .cer or .p7b file.
cert.LoadFromFile(@"D:\AttidoMobile\pass.cer");
crypt.SetSigningCertificate(cert);

// Create the signature.
byte [] signature = crypt.CreateSignature(pdfBytes);

// Save the signature to a file.
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(
    System.IO.File.Create(@"D:\AttidoMobile\signature"));
bw.Write(signature);
bw.Close();

// Now load the signature back into another byte array.
fInfo = new System.IO.FileInfo(@"D:\AttidoMobile\signature");
br = new System.IO.BinaryReader(
    System.IO.File.OpenRead(@"D:\AttidoMobile\signature"));
byte [] sigBytes = br.ReadBytes((int)fInfo.Length);
br.Close();

// This should be valid.
bool valid1 = crypt.VerifySignature(pdfBytes,sigBytes);

// Modify the data, and verify should return false.
pdfBytes[0] = 0xCC;
bool valid2 = crypt.VerifySignature(pdfBytes,sigBytes);

Console.WriteLine("valid1 = " + valid1 + ", valid2 = " + valid2);

}

// Define other methods and classes here


Accepted Answer

The LastErrorText property is the place to get information about what transpired in any given Chilkat method call. Turn on the VerboseLogging property to get more verbose information in LastErrorText.

When faced with a problem, the 1st step in solving it is to ask the question: Where and how can I get information about what happened? The answer to that question w/Chilkat is always the LastErrorText property. (There may be other properties that can help -- make sure to review the reference documentation -- there may be a SessionLog property, or a "fail reason" property, etc.)


Answer

Ok, so I figured it out... Apparently the certificate also has to be in the certificate store. you just can't load the .cer file. I did all that and now its working on my new machine. The Last.ErrorText is what helped me though, so thanks for the tip!!!!