/// <summary>
        /// This function shows how to checkout a document using encryption functionality of
        /// It does not set the ix.Ix.cryptDocuments session option. It assigns "&crypt=true"
        /// to the URL to direct IndexServer to decrypt the document.
        /// Using this method does not require an extra call to DM. But the file size and file extension
        /// in the DocVersion object comes from the encrypted document (ETF-file) rather the
        /// original document.
        /// </summary>
        /// <param name="ix"></param>
        /// <param name="CONST"></param>
        /// <param name="ci"></param>
        /// <param name="objId"></param>
        private void checkoutDocDecryptedUsingUrlExt(IXConnection ix, IXServicePortC CONST, string objId)
        {
            // Tell IndexServer not to encrypt/decrypt.
            setSessionOptionEncrypt(ix, false);

            // Provide external password of encryption set.
            string encrPwd = ix.EncryptPassword(encryptionPassword);

            ix.Ix.provideCryptPassword("" + encryptionSet, encrPwd);

            EditInfo ed = ix.Ix.checkoutDoc(objId, null, EditInfoC.mbSordDoc, LockC.NO);

            Logger.instance().log("encrypted.ext=" + ed.document.docs[0].ext);
            Logger.instance().log("encrypted.size=" + ed.document.docs[0].size);
            String tempName2 = internalMakeTempFileName(".tmp");

            // append the special parameter to the URL
            String urlDecr = ed.document.docs[0].url + "&crypt=true";

            Logger.instance().log("prepared download URL=" + urlDecr);

            // -------------------------------------------------------------------------------
            // The URL to download the document should be a HTTPS URL in production environments!
            // IndexServer configuration option "ixUrlBase" might be helpful here.
            // -------------------------------------------------------------------------------

            ix.Download(urlDecr, tempName2);

            // Show document in notepad:
            System.Diagnostics.Process.Start("notepad.exe", tempName2);
            System.Threading.Thread.Sleep(3000);

            System.IO.File.Delete(tempName2);
        }
        /// <summary>
        /// This function shows how to checkin a document using encryption functionality of
        /// </summary>
        /// <param name="ix"></param>
        /// <param name="CONST"></param>
        /// <param name="ci"></param>
        /// <returns></returns>
        private string checkinDocEncrypted(IXConnection ix, IXServicePortC CONST)
        {
            // Tell IndexServer to encrypt/decrypt.
            setSessionOptionEncrypt(ix, true);

            // Provide external password of encryption set.
            // This password must be encrpyted for security reasons.
            // Administrators should not know it!
            string encrPwd = ix.EncryptPassword(encryptionPassword);

            ix.Ix.provideCryptPassword("" + encryptionSet, encrPwd);

            // Create document
            EditInfo ed = ix.Ix.createDoc("1", "0", null, EditInfoC.mbSordDoc);

            ed.sord.name = "C# example CheckinOutDocEncrypted";
            ed.sord.details.encryptionSet = encryptionSet;

            // Create file for document version
            String testFile = internalCreateTestFile("CheckinDocEncrypted example file", "txt");

            // Supply the extension of the document
            ed.document.docs                  = new DocVersion[1];
            ed.document.docs[0]               = new DocVersion();
            ed.document.docs[0].ext           = ix.GetFileExt(testFile);
            ed.document.docs[0].pathId        = ed.sord.path;
            ed.document.docs[0].encryptionSet = ed.sord.details.encryptionSet;

            // CheckinDocBegin: let IndexServer generate an URL to upload the document
            // This URL addresses always the IndexServer and not the Document Manager.
            ed.document = ix.Ix.checkinDocBegin(ed.document);

            // -------------------------------------------------------------------------------
            // The URL to upload the document should be a HTTPS URL in production environments!
            // IndexServer configuration option "ixUrlBase" might be helpful here.
            // -------------------------------------------------------------------------------

            Logger.instance().log("prepared upload URL=" + ed.document.docs[0].url + ", doc-guid=" + ed.document.docs[0].guid);

            // Upload document version.
            // IndexServer encrypts the document.
            ed.document.docs[0].uploadResult = ix.Upload(ed.document.docs[0].url, testFile);
            Logger.instance().log("upload document version succeeded");

            // CheckinDocEnd: uploadResult contains the document information from ELODM.
            // Pass this information to
            ed.document = ix.Ix.checkinDocEnd(ed.sord, SordC.mbAll, ed.document, LockC.NO);
            Logger.instance().log("inserted document:");
            Logger.instance().log("  objId=" + ed.document.objId);
            Logger.instance().log("  docId=" + ed.document.docs[0].id);
            Logger.instance().log("  doc-guid=" + ed.document.docs[0].guid);
            Logger.instance().log("  URL=" + ed.document.docs[0].url);

            System.IO.File.Delete(testFile);

            return(ed.document.objId);
        }
        /// <summary>
        /// This function initializes an encryption set with a new internal and external password.
        /// It must be called with administrator rights.
        /// </summary>
        /// <param name="encrSet">Encryption set ID</param>
        /// <param name="name">Encryption set name</param>
        /// <param name="pwd">External password</param>
        private void initializeNewEncryptionSet(IXConnection ix, IXServicePortC CONST,
                                                int encrSet, String name, String pwd)
        {
            // Create new CryptInfo object that contains the parameters for an encrpytion set
            CryptInfo yi = new CryptInfo();

            yi.id   = encrSet;
            yi.name = name;

            // Encrypt the password with the public key supplied by IndexServer
            yi.pwd = ix.EncryptPassword(pwd);

            // KeyInfo can be filled with the internal ELO representation of the
            // internal encryption key. This information is encrypted with the
            // external password. To create a new internal key, set this member to "*"
            yi.keyInfo = "*";

            // write crypt info
            ix.Ix.checkinCryptInfos(new CryptInfo[] { yi }, LockC.NO);
        }
Exemple #4
0
 /// <summary>
 /// Encrypts passed in password and returns it back.
 /// </summary>
 /// <param name="pwdToEncrypt">Password that have to be encrypted</param>
 /// <returns>
 /// Encrypted password
 /// </returns>
 public string EncryptPassword(string pwdToEncrypt)
 {
     return(internalConnection.EncryptPassword(pwdToEncrypt));
 }