Esempio n. 1
0
        EncryptedPackageEnvelope(
            string envelopeFileName,
            Stream packageStream,
            PublishLicense publishLicense,
            CryptoProvider cryptoProvider
            )
        {
            if (envelopeFileName == null)
            {
                throw new ArgumentNullException("envelopeFileName");
            }

            if (packageStream == null)
            {
                throw new ArgumentNullException("packageStream");
            }

            ThrowIfRMEncryptionInfoInvalid(publishLicense, cryptoProvider);

            _root = StorageRoot.Open(
                envelopeFileName,
                _defaultFileModeForCreate,
                _defaultFileAccess,
                _defaultFileShare
                );

            InitializeRMForCreate(publishLicense, cryptoProvider);
            EmbedPackage(packageStream);
        }
Esempio n. 2
0
        IsEncryptedPackageEnvelope(
            string fileName
            )
        {
            bool retval = false;

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            StorageRoot root = null;

            try
            {
                //
                // When StorageRoot.Open is called on a file that is not a compound file,
                // it throws an IOException whose inner exception is a COMException whose
                // error code is 0x80030050, STG_E_FILEALREADYEXISTS. Check for that case
                // and return false because that means that this is not an RM-protected file.
                //
                // Any other exception is a real error. For example, StorageRoot.Open
                // throws FileNotFoundException if path does not exist, and we let that
                // flow through.
                //
                root = StorageRoot.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                //
                // It's a compound file. Does it contain an "EncryptedPackage" stream?
                //
                retval = ContainsEncryptedPackageStream(root);
            }
            catch (IOException ex)
            {
                COMException comException = ex.InnerException as COMException;
                if (comException != null && comException.ErrorCode == STG_E_FILEALREADYEXISTS)
                {
                    return(false);
                }

                throw;  // Any other kind of IOException is a real error.
            }
            finally
            {
                if (root != null)
                {
                    root.Close();
                }
            }

            return(retval);
        }
Esempio n. 3
0
        EncryptedPackageEnvelope(
            string envelopeFileName,
            FileAccess access,
            FileShare sharing
            )
        {
            if (envelopeFileName == null)
            {
                throw new ArgumentNullException("envelopeFileName");
            }

            _root = StorageRoot.Open(
                envelopeFileName,
                _defaultFileModeForOpen,
                access,
                sharing
                );

            InitForOpen();
        }