コード例 #1
0
        /// <summary>
        /// Load The Encrypted Persisted cwActivation Object
        /// </summary>
        /// <returns></returns>
        static private bool LoadStegan()
        {
            bool retValue = false;
            int  i        = 0;

            //byte[] fileContents;
            byte[] fileContents;
            fileContents = cwStegan.LoadSteganonographedFile(m_FileName);
            try
            {
                //FileStream						inputStream		= File.Open(m_FileName, FileMode.Open,FileAccess.Read);

                BinaryFormatter          binaryFormatter = new BinaryFormatter();
                DESCryptoServiceProvider DES             = new DESCryptoServiceProvider();
                StreamReader             sr;

                //A 64 bit key and IV is required for this provider.
                //Set secret key For DES algorithm.
                DES.Key = ASCIIEncoding.ASCII.GetBytes(m_enck);
                //Set initialization vector.

                DES.IV = ASCIIEncoding.ASCII.GetBytes(m_enck);

                //Create a DES decryptor from the DES instance.
                ICryptoTransform desdecrypt = DES.CreateDecryptor();
                //Create crypto stream set to read and do a
                //DES decryption transform on incoming bytes.

                //Print the contents of the decrypted file.
                //fileContents = new byte[iobjectStream.Length];
                //iobjectStream.Read(fileContents,0,(int)iobjectStream.Length);
                MemoryStream objectStream     = new MemoryStream((int)fileContents.Length);
                CryptoStream cryptostreamDecr = new CryptoStream(objectStream,
                                                                 desdecrypt,
                                                                 CryptoStreamMode.Write);

                cryptostreamDecr.Write(fileContents, 0, (int)fileContents.Length);
                cryptostreamDecr.FlushFinalBlock();

                objectStream.Position = 0;                 //Rewind the memory stream.
                cwActivation          = (CWActivation)binaryFormatter.Deserialize(objectStream);
                //Clean Up;
                cryptostreamDecr.Close();
                objectStream.Close();
                //Clear Input Stream.
                //inputStream.Flush();
                //objectStream.Close();
                retValue = true;
                PersistStegan();
            }
            catch (Exception exe)
            {
                String temp = exe.Message;
            }
            finally
            {
            }
            return(retValue);
        }
コード例 #2
0
 static CWProductProtection()
 {
     gcHandleenck   = GCHandle.Alloc(m_enck, GCHandleType.Pinned);
     gcHandleenckiv = GCHandle.Alloc(m_enckiv, GCHandleType.Pinned);
     cwStegan       = new CWSteganography();
     m_FileName     = "";
     //m_enck = "7#;t^:SY]-k VFV=1t/;6LjCa*D'H";
     m_enck = "X<cK%3 &";              //A:'H4$~U"; //"X<cK%3 &A:'H4$~U]^";
     //m_enckiv = "7#;t^:SY"; //]-k VFV=1t/;6LjC";
     cwActivation     = new CWActivation();
     m_IsStegan       = false;
     m_ControlsLocked = false;
 }