コード例 #1
0
ファイル: RSA.cs プロジェクト: tonichoff/Cryptography
        static public void EncryptFile(string sourceFilePath, string encryptFilePath, string fileKeyPath)
        {
            Console.WriteLine($"Start encrypting");
            var openKey = RSAKey.ReadFromFile(fileKeyPath);

            using (var encodeFile = File.CreateText(encryptFilePath))
            {
                var bytesFromSourceFile = File.ReadAllBytes(sourceFilePath);
                var isFirstByte         = true;
                var count = 0;
                foreach (byte @byte in bytesFromSourceFile)
                {
                    Console.WriteLine($"Byte number {count++} from {bytesFromSourceFile.Length}");
                    var code = Encrypt(new BigInteger(@byte), openKey);
                    if (!isFirstByte)
                    {
                        encodeFile.Write(Separator);
                    }
                    else
                    {
                        isFirstByte = false;
                    }
                    encodeFile.Write(code);
                }
            }
        }
コード例 #2
0
ファイル: RSA.cs プロジェクト: tonichoff/Cryptography
        static public void DecryptFile(string encryptFilePath, string decryptFilePath, string fileKeyPath)
        {
            Console.WriteLine($"Start decrypting");
            var closeKey = RSAKey.ReadFromFile(fileKeyPath);

            using (var decodedFile = File.Create(decryptFilePath))
            {
                var encodedInformation = File.ReadAllText(encryptFilePath).Split(Separator);
                var count = 0;
                foreach (var block in encodedInformation)
                {
                    Console.WriteLine($"Byte number {count++} from {encodedInformation.Length}");
                    var decodedBlock = Decrypt(BigInteger.Parse(block), closeKey).ToByteArray()[0];
                    decodedFile.WriteByte(decodedBlock);
                }
            }
        }