Ejemplo n.º 1
0
        public V2DocumentHeaders(EncryptionParameters encryptionParameters, long keyWrapIterations)
        {
            if (encryptionParameters == null)
            {
                throw new ArgumentNullException("encryptionParameters");
            }

            _headers = new Headers();

            _headers.HeaderBlocks.Add(new PreambleHeaderBlock());
            _headers.HeaderBlocks.Add(new VersionHeaderBlock(_version));

            ICryptoFactory       cryptoFactory    = Resolve.CryptoFactory.Create(encryptionParameters.CryptoId);
            IDerivedKey          keyEncryptingKey = cryptoFactory.CreateDerivedKey(encryptionParameters.Passphrase);
            V2KeyWrapHeaderBlock keyWrap          = new V2KeyWrapHeaderBlock(cryptoFactory, keyEncryptingKey, keyWrapIterations);

            _headers.HeaderBlocks.Add(keyWrap);
            _keyStreamFactory = keyWrap;

            foreach (UserPublicKey publicKey in encryptionParameters.PublicKeys)
            {
                _headers.HeaderBlocks.Add(new V2AsymmetricKeyWrapHeaderBlock(publicKey, keyWrap.MasterKey, keyWrap.MasterIV));
            }
            _headers.HeaderBlocks.Add(new V2AsymmetricRecipientsEncryptedHeaderBlock(GetHeaderCrypto(HeaderBlockType.AsymmetricRecipients))
            {
                Recipients = new Recipients(encryptionParameters.PublicKeys)
            });
            _headers.HeaderBlocks.Add(new FileInfoEncryptedHeaderBlock(GetHeaderCrypto(HeaderBlockType.FileInfo)));
            _headers.HeaderBlocks.Add(new V2CompressionEncryptedHeaderBlock(GetHeaderCrypto(HeaderBlockType.Compression)));
            _headers.HeaderBlocks.Add(new V2UnicodeFileNameInfoEncryptedHeaderBlock(GetHeaderCrypto(HeaderBlockType.UnicodeFileNameInfo)));
            _headers.HeaderBlocks.Add(new V2AlgorithmVerifierEncryptedHeaderBlock(GetHeaderCrypto(HeaderBlockType.AlgorithmVerifier)));
            _headers.HeaderBlocks.Add(new DataHeaderBlock());

            SetDataEncryptingCryptoForEncryptedHeaderBlocks(_headers.HeaderBlocks);
        }
            public WrapIterator(Guid cryptoId)
            {
                ICryptoFactory factory = Resolve.CryptoFactory.Create(cryptoId);

                _dummyCrypto = factory.CreateCrypto(factory.CreateDerivedKey(new Passphrase("A dummy passphrase")).DerivedKey, null, 0);
                _dummySalt   = new Salt(_dummyCrypto.Key.Size);
                _dummyKey    = new SymmetricKey(_dummyCrypto.Key.Size);
            }