Ejemplo n.º 1
0
        public string crypt(string str, PasswordSecure pwd = null)
        {
            if (pwd == null)
            {
                pwd = key;
            }

            var sha = new SHA3(str.Length);

            if (random == null)
            {
                var inits = str + DateTime.Now.ToString("r");
                var t     = new UTF32Encoding().GetBytes(inits);
                var bbi   = new BytesBuilder();
                bbi.add(t);
                bbi.add(sha.CreateInitVector(0, 64, 40));
                var init = bbi.getBytes();

                random = new SHA3.SHA3Random(init);

                bbi.clear();
                BytesBuilder.ClearString(inits);
                BytesBuilder.ToNull(init);
            }

            var bytes = new UTF32Encoding().GetBytes(str);

            var openKey = pwd.getObjectValue();
            var crypted = sha.multiCryptLZMA(bytes, openKey, null, 22, false);

            BytesBuilder.BytesToNull(openKey);
            BytesBuilder.BytesToNull(bytes);
            BytesBuilder.ClearString(str);

            return(Convert.ToBase64String(crypted));
        }