public void Decrypt(string sousreFileName, string destFileName, string keyFilename)
        {
            RSAKey     privateKey       = KeyFileReader.ReadKey(keyFilename);
            FileStream sourseFileStream = new FileStream(sousreFileName, FileMode.Open);
            FileStream destFileStream   = new FileStream(destFileName, FileMode.Create);

            using (BinaryWriter binaryWriter = new BinaryWriter(destFileStream))
            {
                using (BinaryReader binaryReader = new BinaryReader(sourseFileStream))
                {
                    while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
                    {
                        binaryWriter.Write(Convert.ToByte(PowModFast(binaryReader.ReadInt64(), privateKey.data, privateKey.N)));
                    }
                }
            }
            sourseFileStream.Close();
            destFileStream.Close();
        }
Exemple #2
0
        public void Encrypt(string sourceFileName, string destinationFileName, string keyFileName)
        {
            RSAKey     publickey             = KeyFileReader.ReadKey(keyFileName);
            FileStream sourceFileStream      = new FileStream(sourceFileName, FileMode.Open);
            FileStream destinationFileStream = new FileStream(destinationFileName, FileMode.Create);

            using (BinaryWriter binaryWriter = new BinaryWriter(destinationFileStream))
            {
                using (BinaryReader binaryReader = new BinaryReader(sourceFileStream))
                {
                    while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
                    {
                        binaryWriter.Write(PowModFast(Convert.ToInt64(binaryReader.ReadByte()), publicKey.Data, publicKey.N));
                    }
                }
            }

            sourceFileStream.Close();
            destinationFileStream.Close();
        }