示例#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);
        }
示例#2
0
        public CompressedDataOpenPgpPacket Compress()
        {
            var compressed = new CompressedDataOpenPgpPacket();

            WriteTo(compressed.DecompressedStream);
            return(compressed);
        }
示例#3
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;
        }
示例#4
0
 public CompressedDataOpenPgpPacket Compress()
 {
     var compressed = new CompressedDataOpenPgpPacket();
     WriteTo(compressed.DecompressedStream);
     return compressed;
 }