Example #1
0
        public void Encrypt()
        {
            var plaintText            = "abc";
            var key                   = "123";
            var expectedEncryptedText = "PPP";

            var start         = Environment.TickCount;
            var encryptedText = xorCipher.Encrypt(plaintText, key);
            var end           = Environment.TickCount;
            var duration      = end - start;

            Console.WriteLine(duration);
            Assert.AreEqual(expectedEncryptedText, encryptedText);
            var decryptedText = xorCipher.Encrypt(encryptedText, key);

            Assert.AreEqual(plaintText, decryptedText);
        }
        public void EncryptLine()
        {
            XorCipher cipher   = new XorCipher();
            string    source   = "Burning 'em, if you ain't quick and nimble" + (char)10 + "I go crazy when I hear a cymbal";
            string    key      = "ICE";
            Hex       expected = new Hex("0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a26226324272765272a282b2f20430a652e2c652a3124333a653e2b2027630c692b20283165286326302e27282f");
            string    result   = cipher.Encrypt(source, key);

            Assert.AreEqual(expected, result);
        }
Example #3
0
        public void XorCipherTest()
        {
            using (var cipher1 = new XorCipher())
                using (var cipher2 = new XorCipher())
                {
                    var content = "password";

                    var passwordEnc = cipher1.Encrypt(Encoding.UTF8.GetBytes(content));
                    Console.Write(string.Join(";", passwordEnc.Select(@byte => $"{@byte:x2}").ToArray()));

                    var password = Encoding.UTF8.GetString(cipher2.Decrypt(passwordEnc));
                    Assert.AreEqual(content, password);
                }
        }
Example #4
0
 public string Encrypt(string plainText, ProductionCipherKey productionCipherKey)
 {
     return(xorCipher.Encrypt(rotateCipher.Encrypt(caesarCipher.Encrypt(plainText, productionCipherKey.ReplaceKey), productionCipherKey.RotateKey), productionCipherKey.Password));
 }
Example #5
0
        public static string XorCrypt(this string value, string password)
        {
            var xorCipher = new XorCipher();

            return(xorCipher.Encrypt(value, password));
        }
        public string GetUserEncryptionPassword(int userId, string salt)
        {
            var currentUser = mtfDatabase.Users.AsNoTracking().Single(user => user.Id == userId);

            return(xorCipher.Encrypt(currentUser.PasswordHash, salt));
        }