Пример #1
0
        /// <summary>Encrypt a file with our CBC.</summary>
        /// <param name="sourceFilename">The full path and name of the file to be encrypted.</param>
        /// <param name="destinationFilename">The full path and name of the file to be output.</param>
        /// <param name="password">The password for the encryption.</param>
        public void EncryptFile(string sourceFilename, string destinationFilename, string password)
        {
            byte[]    key    = Encoding.ASCII.GetBytes(password);
            byte[]    data   = System.IO.File.ReadAllBytes(sourceFilename);
            CbcCypher cypher = new CbcCypher((uint)(key.Length));

            byte[] encodedData = cypher.encrypt(data, key);

            System.IO.File.WriteAllBytes(destinationFilename, encodedData);
        }
Пример #2
0
        public void Should_Be_Equals_After_Encryption()
        {
            BytesGenerator generator = BytesGenerator.getInstance();
            CbcCypher      cypher    = new CbcCypher(128);

            byte[] data        = generator.generateRandom(2048);
            byte[] key         = generator.generateRandom(128);
            byte[] encodedData = cypher.encrypt(data, key);
            byte[] decodedData = cypher.decrypt(encodedData, key);

            string dataString        = BitConverter.ToString(data);
            string decodedDataString = BitConverter.ToString(decodedData);


            Assert.AreEqual(dataString, decodedDataString);
        }