Esempio n. 1
0
    //TODO
    //Chiamo lo storage
    //Calcolo la Hash
    //Ritorna
    //public DocumentContent CalculateBlobHash(Document Document)

    /// <summary>
    /// 
    /// </summary>
    /// <param name="FileName"></param>
    /// <param name="SignerCert"></param>
    /// <param name="SignedDigest"></param>
    /// <param name="Content"></param>
    /// <returns>DocumentContent</returns>
    public DocumentContent AddRawSignature(string FileName, DocumentContent SignerCert, DocumentContent SignedDigest, DocumentContent Content)
    {
        using (CompEdObj p7mO = new CompEdObj())
        {
            int p7kH;
            p7mO.P7mNew(out p7kH);
            p7mO.VerifyLastError();

            p7mO.P7mSetType(p7kH);
            p7mO.VerifyLastError();

            p7mO.AddRawSignature(p7kH, SignedDigest.Blob, SignerCert.Blob);
            p7mO.VerifyLastError();

            p7mO.P7mAddTimeFileDescription(p7kH, "", FileName, "");
            p7mO.VerifyLastError();

            p7mO.P7mContentInit(p7kH);
            p7mO.VerifyLastError();

            p7mO.P7mAddBlob(p7kH, Content.Blob);
            p7mO.VerifyLastError();

            p7mO.P7mContentFinish(p7kH);
            p7mO.VerifyLastError();

            byte[] ret = p7mO.P7kContentReadToBuf(p7kH);
            p7mO.VerifyLastError();

            return new DocumentContent(ret);
        }
    }
Esempio n. 2
0
        public bool GetFileInfo(string format, byte[] blob, out string MetaData)
        {
            var  compedObj = new CompEdObj();
            bool retval    = false;

            try
            {
                switch (format.ToUpper())
                {
                case "P7M":
                    compedObj.GetFileInfo(true, blob, out MetaData);
                    break;

                case "P7X":
                    compedObj.GetFileInfo(false, blob, out MetaData);
                    break;

                default:
                    MetaData = "<?xml version=\"1.0\" ?><file name=\"\" description=\"\"";
                    break;
                }

                SHA1   sha     = new SHA1CryptoServiceProvider();
                byte[] docHash = sha.ComputeHash(blob);

                MetaData += " containerHash=\"" + CompEdObj.ByteToHex(docHash) + "\"></file>";

                retval = true;
            }
            finally
            {
                compedObj.Dispose();
            }

            return(retval);
        }
Esempio n. 3
0
 //TODO Verificare se lasciare o togliere.
 public DocumentContent CalculateBlobHash(DocumentContent Content, ComputeHashType computeHash)
 {
     return new DocumentContent(CompEdObj.CalculateBlobHash(Content.Blob, computeHash));
 }