コード例 #1
0
        public void BuildFilterConfigHash_ShouldBeAffectedByEventLogName()
        {
            var original  = new FilterConfiguration("filter", TimeSpan.FromHours(1), 100, "foobar", "bazqux");
            var newConfig = new FilterConfiguration("filter", TimeSpan.FromHours(1), 100, "foobar", "foobar");

            Assert.That(HashBuilder.BuildFilterConfigHash(original), Is.Not.EqualTo(HashBuilder.BuildFilterConfigHash(newConfig)));
        }
コード例 #2
0
        public static TicketState CheckTicket(string ticket, string clientIp, out string userId)
        {
            userId = null;
            string realData = CryptHelper.Decrypt(PrivateKeyPath, ticket);

            //验证解密非空
            if (string.IsNullOrEmpty(realData))
            {
                return(TicketState.Invalid);
            }

            string[] splitData = realData.Split('&');
            //验证数字签名
            if (HashBuilder.GetHMACMD5Hash(splitData[0] + splitData[1] + splitData[2] + splitData[3]).Equals(splitData[4]) == false)
            {
                return(TicketState.Invalid);
            }
            //验证ip
            if (splitData[1].Equals(clientIp) == false)
            {
                return(TicketState.Invalid);
            }
            //验证是否过期
            if (Convert.ToInt32((DateTime.Now - Convert.ToDateTime(splitData[2])).TotalMinutes) > Convert.ToInt32(splitData[3]))
            {
                return(TicketState.Expired);
            }
            //到此验证通过
            userId = splitData[0];
            return(TicketState.Valid);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ysuzuki5321/Othello
        static void Main(string[] args)
        {
            var sha256 = new System.Security.Cryptography.SHA256Managed();

            Console.WriteLine(HashBuilder.Build("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"));
            Console.ReadKey();
        }
コード例 #4
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Null_Values_Considered_Equal()
    {
        byte?  a1 = null;
        string?b1 = null;

        byte[]? c1 = null;

        var hash1 = new HashBuilder()
                    .Add(a1)
                    .Add(b1)
                    .Add(c1)
                    .GetHash();

        long?    a2 = null;
        object?  b2 = null;
        DateTime?c2 = null;

        var hash2 = new HashBuilder()
                    .Add(a2)
                    .Add(b2)
                    .Add(c2)
                    .GetHash();

        hash2.Should().Be(hash1);
    }
コード例 #5
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Avoid_Confusion_Between_List_And_Single_Item()
    {
        var hash1 = new HashBuilder().Add(1).GetHash();
        var hash2 = new HashBuilder().Add(new[] { 1 }).GetHash();

        hash2.Should().NotBe(hash1);
    }
コード例 #6
0
        /// <summary>
        /// 校验Token
        /// </summary>
        /// <param name="token">待校验的Token字符串</param>
        /// <param name="userId">输出型参数,若校验通过值为userId,否则值为null</param>
        /// <returns>Token校验结果。Valid:校验通过; Invalid:不合法的Token,校验失败; Expired:过期的Token,校验失败</returns>
        public string CheckToken(string token, out string userId)
        {
            userId = null;
            //如果token长度不为256,肯定不合法
            if (token.Length != 256)
            {
                return(TokenState.Invalid.ToString());
            }
            string realData = CryptHelper.Decrypt(PrivateKeyPath, token);

            //验证解密非空,否则token不合法
            if (string.IsNullOrEmpty(realData))
            {
                return(TokenState.Invalid.ToString());
            }

            string[] splitData = realData.Split('&');
            //验证数字签名
            if (HashBuilder.GetHMACMD5Hash(splitData[0] + splitData[1] + splitData[2]).Equals(splitData[3]) == false)
            {
                return(TokenState.Invalid.ToString());
            }

            //验证是否过期
            if (Convert.ToInt32((DateTime.Now - Convert.ToDateTime(splitData[1])).TotalMinutes) > Convert.ToInt32(splitData[2]))
            {
                return(TokenState.Expired.ToString());
            }
            //到此验证通过
            userId = splitData[0];
            return(TokenState.Valid.ToString());
        }
コード例 #7
0
        public XamlFileDefinition(string file)
        {
            Namespaces = new List <NamespaceDeclaration>();
            Objects    = new List <XamlObjectDefinition>();
            FilePath   = file;

            UniqueID = SanitizedFileName + "_" + HashBuilder.Build(FilePath);
        }
コード例 #8
0
        //title="userId & createTime & expiredDuration & 签名"

        /// <summary>
        /// 创建Token
        /// </summary>
        /// <param name="UserId">当前用户ID</param>
        /// <param name="expiredDuration">Token的有效时长(单位:分钟)</param>
        /// <returns>Token字符串</returns>
        public string CreateToken(string UserId, int expiredDuration)
        {
            string timeStamp  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string strHashed  = HashBuilder.GetHMACMD5Hash(UserId + timeStamp + expiredDuration.ToString());
            string concatData = UserId + "&" + timeStamp + "&" + expiredDuration.ToString() + "&" + strHashed;

            return(CryptHelper.Encrypt(PublicKeyPath, concatData));
        }
コード例 #9
0
        public void BuildEventIdentification_ShouldNotBeAffectedByIndex()
        {
            var hash1 = HashBuilder.BuildEventIdentification(_logEvent).Hash;

            _logEvent.Index = 123;
            var hash2 = HashBuilder.BuildEventIdentification(_logEvent).Hash;

            Assert.That(hash1, Is.EqualTo(hash2));
        }
コード例 #10
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Avoid_Confusion_Between_Floating_Types()
    {
        var hash1 = new HashBuilder().Add((float)0).GetHash();
        var hash2 = new HashBuilder().Add((double)0).GetHash();
        var hash3 = new HashBuilder().Add((decimal)0).GetHash();

        hash2.Should().NotBe(hash1);
        hash3.Should().NotBe(hash2).And.NotBe(hash1);
    }
コード例 #11
0
        private void AssertHashNotSameAfterFunction(Action change)
        {
            var hash1 = HashBuilder.BuildEventIdentification(_logEvent).Hash;

            change.Invoke();

            var hash2 = HashBuilder.BuildEventIdentification(_logEvent).Hash;

            Assert.That(hash1, Is.Not.EqualTo(hash2));
        }
コード例 #12
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Avoid_Confusion_Between_Integer_Types()
    {
        var hash1 = new HashBuilder().Add((byte)0).GetHash();
        var hash2 = new HashBuilder().Add((short)0).GetHash();
        var hash3 = new HashBuilder().Add(0).GetHash();
        var hash4 = new HashBuilder().Add((long)0).GetHash();

        hash2.Should().NotBe(hash1);
        hash3.Should().NotBe(hash2).And.NotBe(hash1);
        hash4.Should().NotBe(hash3).And.NotBe(hash2).And.NotBe(hash1);
    }
コード例 #13
0
        private static BigInteger GetCacheKey(Type resultType, IMappingExport mappings)
        {
            if (mappings is DefaultResultMapping)
            {
                return(HashBuilder.Compute(resultType.AssemblyQualifiedName));
            }

            return(HashBuilder.Compute(mappings.Export()
                                       .Aggregate(resultType.AssemblyQualifiedName, (seed, kvp)
                                                  => seed + kvp.Key + kvp.Value.ActiveAlias + kvp.Value.PropertyMetadata.Name)));
        }
コード例 #14
0
        public void AddItemsTest2()
        {
            HashBuilder target = new HashBuilder();

            target.AddItems(1, 2, 3, 4, 5);
            int         result1 = target.Result;
            HashBuilder target2 = new HashBuilder();

            target2.AddItems(1, 2, 3, 4, 5);

            Assert.IsTrue(target.Result == target2.Result);
        }
コード例 #15
0
            private void ProcessType(INamedTypeSymbol typeSymbol)
            {
                var isiOSView       = typeSymbol.Is(_iosViewSymbol);
                var ismacOSView     = typeSymbol.Is(_macosViewSymbol);
                var isAndroidView   = typeSymbol.Is(_androidViewSymbol);
                var smallSymbolName = typeSymbol.ToString() !.Replace(typeSymbol.ContainingNamespace + ".", "");

                if (isiOSView || ismacOSView)
                {
                    var nativeCtor = typeSymbol
                                     .GetMethods()
                                     .Where(m => m.MethodKind == MethodKind.Constructor && SymbolEqualityComparer.Default.Equals(m.Parameters.FirstOrDefault()?.Type, _intPtrSymbol))
                                     .FirstOrDefault();

                    if (nativeCtor == null)
                    {
                        _context.AddSource(
                            HashBuilder.BuildIDFromSymbol(typeSymbol),
                            string.Format(
                                BaseClassFormat,
                                typeSymbol.ContainingNamespace,
                                smallSymbolName,
                                NeedsExplicitDefaultCtor(typeSymbol),
                                typeSymbol.Name
                                )
                            );
                    }
                }

                if (isAndroidView)
                {
                    var nativeCtor = typeSymbol
                                     .GetMethods()
                                     .Where(m =>
                                            m.MethodKind == MethodKind.Constructor &&
                                            m.Parameters.Select(p => p.Type).SequenceEqual(_javaCtorParams ?? Array.Empty <ITypeSymbol?>()))
                                     .FirstOrDefault();

                    if (nativeCtor == null)
                    {
                        _context.AddSource(
                            HashBuilder.BuildIDFromSymbol(typeSymbol),
                            string.Format(
                                BaseClassFormat,
                                typeSymbol.ContainingNamespace,
                                smallSymbolName,
                                NeedsExplicitDefaultCtor(typeSymbol),
                                typeSymbol.Name
                                )
                            );
                    }
                }
            }
コード例 #16
0
 public Dictionary <string, string> GetTelemetryCommonProperties() => new Dictionary <string, string>
 {
     { OSVersion, RuntimeEnvironment.OperatingSystemVersion },
     { OSPlatform, RuntimeEnvironment.OperatingSystemPlatform.ToString() },
     { OutputRedirected, Console.IsOutputRedirected.ToString() },
     { RuntimeId, RuntimeEnvironment.GetRuntimeIdentifier() },
     { ProductVersion, GetProductVersion() },
     { TelemetryProfile, Environment.GetEnvironmentVariable(TelemetryProfileEnvironmentVariable) },
     { MachineId, GetMachineId() },
     { CurrentPathHash, HashBuilder.Build(_getCurrentDirectory(), SHA256.Create()) },
     { KernelVersion, GetKernelVersion() },
 };
コード例 #17
0
        protected override void Seed(ImageContext context)
        {
            var users = context.Set <User>();

            if (users.All(p => p.CameraSettings != null && p.AppSettings != null) &&
                users.FirstOrDefault(x => x.Name == "admin") != null)
            {
                return;
            }

            var defaultCameraSets =
                StringToByteArray(
                    "3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C43616D65726153657474696E677344746F20786D6C6E733A7873693D22687474703A2F2F7777772E77332E6F72672F323030312F584D4C536368656D612D696E7374616E63652220786D6C6E733A7873643D22687474703A2F2F7777772E77332E6F72672F323030312F584D4C536368656D61223E0D0A20203C53656C656374656441654D6F64653E50726F6772616D3C2F53656C656374656441654D6F64653E0D0A20203C53656C6563746564436F6D70656E736174696F6E3E5A65726F3C2F53656C6563746564436F6D70656E736174696F6E3E0D0A20203C53656C6563746564576869746542616C616E63653E4175746F3C2F53656C6563746564576869746542616C616E63653E0D0A20203C53656C656374656449736F53656E73697469766974793E4175746F3C2F53656C656374656449736F53656E73697469766974793E0D0A20203C53656C65637465645368757474657253706565643E42756C623C2F53656C65637465645368757474657253706565643E0D0A20203C53656C6563746564417656616C75653E41565F343C2F53656C6563746564417656616C75653E0D0A20203C53656C656374656450686F746F41654D6F64653E50726F6772616D3C2F53656C656374656450686F746F41654D6F64653E0D0A20203C53656C656374656450686F746F436F6D70656E736174696F6E3E5A65726F3C2F53656C656374656450686F746F436F6D70656E736174696F6E3E0D0A20203C53656C656374656450686F746F576869746542616C616E63653E4175746F3C2F53656C656374656450686F746F576869746542616C616E63653E0D0A20203C53656C656374656450686F746F49736F53656E73697469766974793E4175746F3C2F53656C656374656450686F746F49736F53656E73697469766974793E0D0A20203C53656C656374656450686F746F5368757474657253706565643E42756C623C2F53656C656374656450686F746F5368757474657253706565643E0D0A20203C53656C656374656450686F746F417656616C75653E41565F343C2F53656C656374656450686F746F417656616C75653E0D0A3C2F43616D65726153657474696E677344746F3E");
            var defaultAppSets =
                StringToByteArray(
                    "3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C41707053657474696E677344746F20786D6C6E733A7873693D22687474703A2F2F7777772E77332E6F72672F323030312F584D4C536368656D612D696E7374616E63652220786D6C6E733A7873643D22687474703A2F2F7777772E77332E6F72672F323030312F584D4C536368656D61223E0D0A20203C53686F775072696E7465724F6E537461727475703E66616C73653C2F53686F775072696E7465724F6E537461727475703E0D0A20203C4461746553746172743E323031362D30342D30345432323A30303A30303C2F4461746553746172743E0D0A20203C44617465456E643E323031362D30342D30345432323A30353A30303C2F44617465456E643E0D0A20203C48617368546167202F3E0D0A20203C4D61785072696E746572436F706965733E313C2F4D61785072696E746572436F706965733E0D0A3C2F41707053657474696E677344746F3E");

            foreach (var item in users)
            {
                if (item.CameraSettings == null)
                {
                    item.CameraSettings = defaultCameraSets;
                }
                if (item.AppSettings == null)
                {
                    item.AppSettings = defaultAppSets;
                }
            }

            if (users.FirstOrDefault(x => x.Name == "admin") != null)
            {
                return;
            }

            var hashBuilder     = new HashBuilder();
            var defaultPassword = hashBuilder.HashPassword("123456");

            users.AddOrUpdate(x => x.Name,
                              new User
            {
                Name           = "admin",
                Password       = defaultPassword,
                CameraSettings = defaultCameraSets,
                AppSettings    = defaultAppSets
            });
            //todo
            //context.Set<Pattern>().AddOrUpdate(x => x.PatternType, Enum.GetValues(typeof (PatternType))
            //    .OfType<PatternType>()
            //    .Select(x => new Pattern(x.GetDescription(), x)).ToArray());
        }
コード例 #18
0
            private void ProcessType(INamedTypeSymbol typeSymbol)
            {
                var isDependencyObject = typeSymbol.Interfaces.Any(t => t == _dependencyObjectSymbol) &&
                                         (typeSymbol.BaseType?.GetAllInterfaces().None(t => t == _dependencyObjectSymbol) ?? true);

                if (isDependencyObject && typeSymbol.TypeKind == TypeKind.Class)
                {
                    var builder = new IndentedStringBuilder();
                    builder.AppendLineInvariant("// <auto-generated>");
                    builder.AppendLineInvariant("// ******************************************************************");
                    builder.AppendLineInvariant("// This file has been generated by Uno.UI (DependencyObjectGenerator)");
                    builder.AppendLineInvariant("// ******************************************************************");
                    builder.AppendLineInvariant("// </auto-generated>");
                    builder.AppendLine();
                    builder.AppendLineInvariant("#pragma warning disable 1591 // Ignore missing XML comment warnings");
                    builder.AppendLineInvariant($"using System;");
                    builder.AppendLineInvariant($"using System.Linq;");
                    builder.AppendLineInvariant($"using System.Collections.Generic;");
                    builder.AppendLineInvariant($"using System.Collections;");
                    builder.AppendLineInvariant($"using System.Diagnostics.CodeAnalysis;");
                    builder.AppendLineInvariant($"using Uno.Disposables;");
                    builder.AppendLineInvariant($"using System.Runtime.CompilerServices;");
                    builder.AppendLineInvariant($"using Uno.Extensions;");
                    builder.AppendLineInvariant($"using Uno.Logging;");
                    builder.AppendLineInvariant($"using Uno.UI;");
                    builder.AppendLineInvariant($"using Uno.UI.DataBinding;");
                    builder.AppendLineInvariant($"using Windows.UI.Xaml;");
                    builder.AppendLineInvariant($"using Windows.UI.Xaml.Data;");
                    builder.AppendLineInvariant($"using Uno.Diagnostics.Eventing;");

                    using (builder.BlockInvariant($"namespace {typeSymbol.ContainingNamespace}"))
                    {
                        if (typeSymbol.FindAttribute(_bindableAttributeSymbol) == null)
                        {
                            builder.AppendLineInvariant(@"[global::Windows.UI.Xaml.Data.Bindable]");
                        }

                        using (GenerateNestingContainers(builder, typeSymbol))
                        {
                            using (builder.BlockInvariant($"{typeSymbol.GetAccessibilityAsCodeString()} partial class {typeSymbol.Name} : IDependencyObjectStoreProvider, IWeakReferenceProvider"))
                            {
                                GenerateDependencyObjectImplementation(builder);
                                GenerateIBinderImplementation(typeSymbol, builder);
                            }
                        }
                    }

                    _context.AddCompilationUnit(HashBuilder.BuildIDFromSymbol(typeSymbol), builder.ToString());
                }
            }
コード例 #19
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Avoid_Confusion_Between_List_And_Many_Items()
    {
        var hash1 = new HashBuilder().Add(1).Add(2).Add(3).GetHash();
        var hash2 = new HashBuilder().AddMany(1, 2, 3).GetHash();

        hash2.Should().Be(hash1);

        var hash3 = new HashBuilder().Add(new[] { 1, 2, 3 }).GetHash();

        hash3.Should().NotBe(hash2);

        var hash4 = new HashBuilder().AddMany(new[] { 1, 2, 3 }).GetHash();

        hash4.Should().Be(hash3);
    }
コード例 #20
0
        public void AddItemsTest1()
        {
            HashBuilder target = new HashBuilder();

            int[] arr = new int[] { 1, 2, 3, 4, 5 };

            target.AddItems((IEnumerable <int>)arr);

            int         result1 = target.Result;
            HashBuilder target2 = new HashBuilder();

            target2.AddItems((IEnumerable <int>)arr);

            Assert.IsTrue(target.Result == target2.Result);
        }
コード例 #21
0
        public static byte[] Serialize(T message)
        {
            var key = HashBuilder.GenerateHash <T>(message);

            byte[] value;

            if (Cache.TryGetValue(key, out value))
            {
                return(value);
            }

            value = SerializerFunc(message);
            Cache.Add(key, value);

            return(value);
        }
コード例 #22
0
            private void ProcessType(INamedTypeSymbol typeSymbol)
            {
                var isiOSView       = typeSymbol.Is(_iosViewSymbol);
                var ismacOSView     = typeSymbol.Is(_macosViewSymbol);
                var isAndroidView   = typeSymbol.Is(_androidViewSymbol);
                var smallSymbolName = typeSymbol.ToString() !.Replace(typeSymbol.ContainingNamespace + ".", "");

                if (isiOSView || ismacOSView)
                {
                    Func <IMethodSymbol, bool> predicate = m => !m.Parameters.IsDefaultOrEmpty && SymbolEqualityComparer.Default.Equals(m.Parameters[0].Type, _intPtrSymbol);
                    var nativeCtor = GetNativeCtor(typeSymbol, predicate, considerAllBaseTypes: false);

                    if (nativeCtor == null && GetNativeCtor(typeSymbol.BaseType, predicate, considerAllBaseTypes: true) != null)
                    {
                        _context.AddSource(
                            HashBuilder.BuildIDFromSymbol(typeSymbol),
                            string.Format(
                                BaseClassFormat,
                                typeSymbol.ContainingNamespace,
                                smallSymbolName,
                                NeedsExplicitDefaultCtor(typeSymbol),
                                SyntaxFacts.GetKeywordKind(typeSymbol.Name) == SyntaxKind.None ? typeSymbol.Name : "@" + typeSymbol.Name
                                )
                            );
                    }
                }

                if (isAndroidView)
                {
                    Func <IMethodSymbol, bool> predicate = m => m.Parameters.Select(p => p.Type).SequenceEqual(_javaCtorParams ?? Array.Empty <ITypeSymbol?>());
                    var nativeCtor = GetNativeCtor(typeSymbol, predicate, considerAllBaseTypes: false);

                    if (nativeCtor == null && GetNativeCtor(typeSymbol.BaseType, predicate, considerAllBaseTypes: true) != null)
                    {
                        _context.AddSource(
                            HashBuilder.BuildIDFromSymbol(typeSymbol),
                            string.Format(
                                BaseClassFormat,
                                typeSymbol.ContainingNamespace,
                                smallSymbolName,
                                NeedsExplicitDefaultCtor(typeSymbol),
                                SyntaxFacts.GetKeywordKind(typeSymbol.Name) == SyntaxKind.None ? typeSymbol.Name : "@" + typeSymbol.Name
                                )
                            );
                    }
                }
コード例 #23
0
    private static bool ProcessModule(string name, Module info)
    {
        var modulePath  = $"../../../../Atom/{info.Category}/{name}";
        var moduleFiles = Directory.GetFiles(modulePath);

        var codeFiles   = moduleFiles.Where(f => Path.GetExtension(f) == ".cs").OrderBy(f => f).ToList();
        var hashBuilder = new HashBuilder();

        foreach (var file in codeFiles)
        {
            hashBuilder.Add(Path.GetFileName(file));
            hashBuilder.Add(File.ReadAllText(file));
        }
        var sourceHash = hashBuilder.GetHash();

        // normalize tags, if needed
        info.Tags = info.Tags.AsCommaList().ToCommaList();

        // sort dependencies, if needed
        if (info.DependsOn != null)
        {
            info.DependsOn = info.DependsOn.OrderBy(i => i).ToArray();
        }

        // if source files have changed then increase build number
        var updated = false;

        if (sourceHash != info.SourceHash)
        {
            var ver = new Version(info.Version);
            var upd = new Version(ver.Major, ver.Minor, ver.Build + 1);

            info.Version      = upd.ToString();
            info.SourceHash   = sourceHash;
            info.ReleaseNotes = "???";
            updated           = true;
        }

        var nuspecFile = Path.Combine(modulePath, $"Atom.{name}.nuspec");
        var nuspecXml  = CreateNuspecXml(name, info, codeFiles);

        File.WriteAllText(nuspecFile, nuspecXml);

        return(updated);
    }
コード例 #24
0
        public void AddTest1()
        {
            HashBuilder target = new HashBuilder();

            target.Add <int>(2);
            target.Add <int>(1);
            target.Add <int>(4);
            target.Add <int>(3);

            int         result1 = target.Result;
            HashBuilder target2 = new HashBuilder();

            target2.Add <int>(2);
            target2.Add <int>(1);
            target2.Add <int>(4);
            target2.Add <int>(3);

            Assert.IsTrue(target.Result == target2.Result);
        }
コード例 #25
0
ファイル: HashBuilderTest.cs プロジェクト: shuruev/Atom
    public void Avoid_Confusion_Between_Null_And_False()
    {
        var hash1 = new HashBuilder().Add(null).Add(null).GetHash();
        var hash2 = new HashBuilder().Add(false).Add(null).GetHash();
        var hash3 = new HashBuilder().Add(null).Add(false).GetHash();
        var hash4 = new HashBuilder().Add(false).Add(false).GetHash();

        hash2.Should().NotBe(hash1);
        hash3.Should().NotBe(hash2).And.NotBe(hash1);
        hash4.Should().NotBe(hash3).And.NotBe(hash2).And.NotBe(hash1);

        hash1 = new HashBuilder().Add(new bool?[] { null, null }).GetHash();
        hash2 = new HashBuilder().Add(new bool?[] { false, null }).GetHash();
        hash3 = new HashBuilder().Add(new bool?[] { null, false }).GetHash();
        hash4 = new HashBuilder().Add(new bool?[] { false, false }).GetHash();
        hash2.Should().NotBe(hash1);
        hash3.Should().NotBe(hash2).And.NotBe(hash1);
        hash4.Should().NotBe(hash3).And.NotBe(hash2).And.NotBe(hash1);
    }
コード例 #26
0
        public static void GetHash()
        {
            Debugger.Write("HashBuilder.Generate...");
            string hash = HashBuilder.Generate("HASH_DEMO");

            hash.Debug();
            Debugger.Write("HashBuilder.Extract...");
            bool extracted = HashBuilder.TryGetHash(hash, out OriHash result);

            if (extracted)
            {
                Debugger.Write("-- Extraction complete. --");
                result.ToString().Debug();
                return;
            }

            Debugger.Write("-- Extraction failed. --");
            return;
        }
コード例 #27
0
        public bool userLogin(string Username, string Password)
        {
            RemotePost req = new RemotePost("http://tickets4you.dk/api/login");

            req.Timeout = 3;

            req.Add("Username", Username);
            req.Add("Password", HashBuilder.GetHashString(Password));
            req.Add("userSession", this.userSession);
            req.Add("apiKey", this.APIKey);

            LoginReturn lr = JsonConvert.DeserializeObject <LoginReturn>(req.Post());

            if (lr.response)
            {
                userSession = lr.key;
            }

            return(lr.response);
        }
コード例 #28
0
        private string GetMachineId()
        {
            try
            {
                var macAddr =
                    (
                        from nic in NetworkInterface.GetAllNetworkInterfaces()
                        where nic.OperationalStatus == OperationalStatus.Up
                        select nic.GetPhysicalAddress().ToString()
                    ).FirstOrDefault();

                return(HashBuilder.Build(macAddr, SHA256.Create()));
            }
            catch (Exception e)
            {
                Debug.Fail($"Failed to get Mac address: {e}");

                return(Guid.NewGuid().ToString());
            }
        }
コード例 #29
0
        private void WritePlugin(plugin p)
        {
            if (p.hotstrings == null)
            {
                return;
            }
            try
            {
                foreach (var hs in p.hotstrings)
                {
                    if (hs.enabled == false)
                    {
                        continue;
                    }
                    switch (hs.type)
                    {
                    case hotstringType.Paste:
                        HashBuilder.AppendLine(hs.UniqueName);
                        this.WriteHotstringPaste(hs);
                        break;

                    case hotstringType.Inline:
                        HashBuilder.AppendLine(hs.UniqueName);
                        this.WriteHotstringInline(hs);
                        break;

                    case hotstringType.Code:
                        HashBuilder.AppendLine(hs.UniqueName);
                        this.WriteHotstringCode(hs);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #30
0
        public static void Seed(CubeDbContext context)
        {
            var password       = "******";
            var systemPassword = "******";

            var adminRole = context.Roles.Add(new Role
            {
                Name = "Админитратор",
                Type = RoleType.Administrator
            });

            context.Roles.Add(new Role
            {
                Name = "Дизайнер",
                Type = RoleType.Designer
            });
            var admin = context.Users.Add(new User
            {
                Name      = "Администратор",
                Login     = "******",
                IsArchive = false,
                Password  = HashBuilder.CreateSha256(password.EncodeToUtf8Bytes()).EncodeBase64()
            });
            var system = context.Users.Add(new User
            {
                Name      = "System",
                Login     = "******",
                IsArchive = false,
                Password  = HashBuilder.CreateSha256(systemPassword.EncodeToUtf8Bytes()).EncodeBase64()
            });

            adminRole.Users.Add(admin);
            adminRole.Users.Add(system);

            context.PriceLists.Add(new PriceList {
                Name = "Основной прайс-лист"
            });

            context.SaveChanges();
        }