Esempio n. 1
0
        public byte[] XOR(byte[] data)
        {
            byte[] keyBytes  = ToBytes();
            var    keyHash   = PromiseUtils.SHA512(keyBytes, 0, keyBytes.Length);
            var    encrypted = new byte[data.Length];

            for (int i = 0; i < encrypted.Length; i++)
            {
                encrypted[i] = (byte)(data[i] ^ keyHash[i % keyHash.Length]);
            }
            return(encrypted);
        }
Esempio n. 2
0
        public static byte[] XOR(byte[] data1, byte[] data2)
        {
            /*
             * Given how the "key" that XOR generates is not the same as the one
             * used in XOR anymore (check step 5), we can't use the "ToBytes()" function since
             * it assumes that the "key" in the XOR step has a size less than N (or "KeySize").
             * So I can either remove the call to the padding function in "ToBytes()" and use
             * the normal XOR function above, or use this independent function and not change
             * anything.
             *
             * If the second choice is better, then this function should move to "Utils" and
             * XOR is no longer needed in PromiseClientSession\PromiseServerSession since the
             * key can be generated directly using "Utils.GenerateEncryptableInteger()".
             */
            var keyHash   = PromiseUtils.SHA512(data1, 0, data1.Length);
            var encrypted = new byte[data2.Length];

            for (int i = 0; i < encrypted.Length; i++)
            {
                encrypted[i] = (byte)(data2[i] ^ keyHash[i % keyHash.Length]);
            }
            return(encrypted);
        }