Example #1
0
        public static Stream EncryptSingleFile(SecureString passphrase, Stream contentsToEncrypt, string fileName, DateTime fileDateTime)
        {
            var msOutput = new MemoryStream();

            var keyPacket = new SymmetricKeyEncryptedSessionKeyOpenPgpPacket();

            keyPacket.WriteTo(msOutput);

            var literalData = new LiteralDataOpenPgpPacket();

            literalData.FileName = fileName;
            literalData.FileDate = fileDateTime;
            contentsToEncrypt.CopyTo(literalData.LiteralStream);

            var compressedPacket = new CompressedDataOpenPgpPacket();

            literalData.WriteTo(compressedPacket.DecompressedStream);

            var symmetricAlgorithm = keyPacket.GetKeyedSymmetricAlgorithm(passphrase);
            var outerPacket        = new SymmetricallyEncryptedIntegrityProtectedDataOpenPgpPacket();

            outerPacket.EncryptPackets(symmetricAlgorithm, compressedPacket);

            outerPacket.WriteTo(msOutput);

            msOutput.Position = 0;
            return(msOutput);
        }
Example #2
0
        public static Stream EncryptSingleFile(SecureString passphrase, Stream contentsToEncrypt, string fileName, DateTime fileDateTime) {
            var msOutput = new MemoryStream();
            
            var keyPacket = new SymmetricKeyEncryptedSessionKeyOpenPgpPacket();
            keyPacket.WriteTo(msOutput);

            var literalData = new LiteralDataOpenPgpPacket();
            literalData.FileName = fileName;
            literalData.FileDate = fileDateTime;
            contentsToEncrypt.CopyTo(literalData.LiteralStream);

            var compressedPacket = new CompressedDataOpenPgpPacket();
            literalData.WriteTo(compressedPacket.DecompressedStream);
            
            var symmetricAlgorithm = keyPacket.GetKeyedSymmetricAlgorithm(passphrase);
            var outerPacket = new SymmetricallyEncryptedIntegrityProtectedDataOpenPgpPacket();
            outerPacket.EncryptPackets(symmetricAlgorithm, compressedPacket);

            outerPacket.WriteTo(msOutput);

            msOutput.Position = 0;
            return msOutput;
        }