Esempio n. 1
0
 public ProductionCipher(CaesarCipher caesarCipher,
                         RotateCipher rotateCipher,
                         XorCipher xorCipher)
 {
     this.caesarCipher = caesarCipher;
     this.rotateCipher = rotateCipher;
     this.xorCipher    = xorCipher;
 }
        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);
        }
Esempio n. 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);
                }
        }
Esempio n. 4
0
        private void ProcessStreamControl(EncryptedStreamControl sc)
        {
            switch (sc)
            {
            case EncryptedStreamControl.EncryptRSA:
            {
                if (!CipherLib.ContainsKey("rsa-private"))
                {
                    throw new SecureChannelException("RSA certificate is required.");
                }

                ReadCipher = CipherLib["rsa-private"].Clone();
                break;
            }

            case EncryptedStreamControl.EncryptXOR:
            {
                var passwLen = ReadUInt16();
                if (passwLen != 0)
                {
                    var passw = ReadData(passwLen);
                    CipherLib["xor"] = new XorCipher(passw);
                }

                ReadStream.Cipher = CipherLib["xor"].Clone();
                break;
            }

            case EncryptedStreamControl.EncryptAES:
            {
                var passwLen = ReadUInt16();
                if (passwLen != 0)
                {
                    var passw = ReadData(passwLen);
                    CipherLib["aes"] = new Aes256Cipher(passw);
                }
                ReadCipher = CipherLib["aes"].Clone();
                break;
            }

            default:
                throw new StreamControlException("Unknown StreamControl command");
            }
        }
Esempio n. 5
0
        public void Encrypt(bool reset = false)
        {
            if (reset)
            {
                WriteStream.Cipher = new XorCipher();
                WriteCipher        = null;
            }

            if (CipherLib.ContainsKey("rsa-public"))
            {
                WriteUInt16((ushort)EncryptedStreamControl.EncryptRSA);
                WriteCipher = CipherLib["rsa-public"].Clone();
            }

            byte[] salt = Random.Get(32);
            WriteUInt16((ushort)EncryptedStreamControl.EncryptAES);
            WriteUInt16((ushort)salt.Length);
            WriteData(salt);
            CipherLib["aes"] = new Aes256Cipher(salt);
            WriteCipher      = CipherLib["aes"].Clone();


            if (!CipherLib.ContainsKey("xor"))
            {
                byte[] passw = Random.Get(2048 / 8);
                WriteUInt16((ushort)EncryptedStreamControl.EncryptXOR);
                WriteUInt16((ushort)passw.Length);
                WriteData(passw);
                CipherLib["xor"] = new XorCipher(passw);
            }
            else
            {
                WriteUInt16((ushort)EncryptedStreamControl.EncryptXOR);
                WriteUInt16((ushort)0);
            }
            WriteStream.Cipher = CipherLib["xor"].Clone();
        }
Esempio n. 6
0
 public XorCracker()
 {
     this.xorCipher = new XorCipher();
 }
Esempio n. 7
0
        public static string XorCrypt(this string value, string password)
        {
            var xorCipher = new XorCipher();

            return(xorCipher.Encrypt(value, password));
        }
 public PasswordHashRepository(XorCipher xorCipher,
                               VirtualWorkDatabaseContext mtfDatabase)
 {
     this.mtfDatabase = mtfDatabase;
     this.xorCipher   = xorCipher;
 }