public ProtoBinaryManager()
        {
            //If you use new line in your password or salt string,
            //Windows machine could produce different result because it uses \r\n instead of just \n
            var password = EncryptionPassword.Replace("\r", "");
            var salt     = EncryptionSalt.Replace("\r", "");

            // Debug.Log(string.Join(" ",Encoding.ASCII.GetBytes(password).Select(x => x.ToString("X"))));
            // Debug.Log(string.Join(" ",Encoding.ASCII.GetBytes(salt).Select(x => x.ToString("X"))));
            derivator = new Rfc2898DeriveBytes(Encoding.ASCII.GetBytes(password), Encoding.ASCII.GetBytes(salt),
                                               EncryptionIteration);
            key = derivator.GetBytes(16);
        }
예제 #2
0
        public IBuffer GetBufferWithoutHMAC()
        {
            bool usesPassword = (Options & (byte)1) == (byte)1;

            using (var ms = new MemoryStream((int)(HEADER_LENGTH + CipherText.Length)))
                using (var writer = new BinaryWriter(ms))
                {
                    writer.Write(Version);
                    writer.Write(Options);
                    if (usesPassword)
                    {
                        writer.Write(EncryptionSalt.ToByteArray());
                        writer.Write(HMACSalt.ToByteArray());
                    }
                    writer.Write(IV.ToByteArray());
                    writer.Write(CipherText.ToByteArray());

                    return(ms.ToArray().ToBuffer());
                }
        }