Beispiel #1
0
        public override byte[] Decode(byte[] secretData)
        {
            int ivN = TEXTSET64.IndexOf((char)secretData[0]);
            var iv  = secretData.Skip(1).Take(16).ToArray();

            using (var rijndael = new RijndaelManaged
            {
                BlockSize = 128,
                KeySize = 128,
                Mode = CipherMode.CBC,
                Padding = PaddingMode.PKCS7,
                IV = iv,
                Key = Encoding.ASCII.GetBytes(FusionString(KEY, MASK)),
            })
            {
                var de = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);
                using (var ms = new MemoryStream(secretData, 17, secretData.Length - 17, false))
                {
                    using (var cs = new CryptoStream(ms, de, CryptoStreamMode.Read))
                    {
                        var ret = new byte[secretData.Length - 17];
                        ms.Read(ret, 0, ret.Length);
                        return(ret);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Make Fusion string
        /// </summary>
        /// <param name="basestr"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private string FusionString(string basestr, string filter)
        {
            var ret    = new StringBuilder(basestr);
            var nB     = basestr.Length;
            var nF     = filter.Length;
            var offset = 0;

            for (var i = Math.Max(nB, nF) - 1; i >= 0; i--)
            {
                ret[i % nB] = TEXTSET64[(TEXTSET64.IndexOf(ret[i % nB]) + (int)filter[i % nF] + OffsetSamples[(i + offset) % OffsetSamples.Length]) % TEXTSET64.Length];
                offset++;
            }
            return(ret.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Rijndael Decoding
        /// </summary>
        /// <param name="secretText"></param>
        /// <returns></returns>
        public override string Decode(string secretText)
        {
            int    ivN = TEXTSET64.IndexOf(secretText[0]);
            string iv  = secretText.Substring(1, ivN + 16);
            string sec = secretText.Substring(ivN + iv.Length + 1);

            using (var rijndael = new RijndaelManaged
            {
                BlockSize = 128,
                KeySize = 128,
                Mode = CipherMode.CBC,
                Padding = PaddingMode.PKCS7,
                IV = Encoding.ASCII.GetBytes(iv),
                Key = Encoding.ASCII.GetBytes(FusionString(KEY, MASK)),
            })
            {
                var de = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV);
                using (var ms = new MemoryStream(Convert.FromBase64String(sec)))
                {
                    using (var cs = new CryptoStream(ms, de, CryptoStreamMode.Read))
                    {
                        using (var sr = new StreamReader(cs))
                        {
                            var ret = sr.ReadToEnd();
                            if (ret == NullDescriptor)
                            {
                                return(null);
                            }
                            else
                            {
                                return(ret);
                            }
                        }
                    }
                }
            }
        }