Ejemplo n.º 1
0
        public static byte[] MD5(Span <byte> input)
        {
            var output = new byte[16];

            MD5Utils.Default(input, output);
            return(output);
        }
Ejemplo n.º 2
0
        public static byte[] MD5(byte[] b)
        {
            var hash = new byte[CryptoBase.MD5Length];

            MD5Utils.Default(b, hash);
            return(hash);
        }
Ejemplo n.º 3
0
        public static byte[] SSKDF(string password, int keylen)
        {
            const int md5Length = 16;
            var       pwMaxSize = Encoding.UTF8.GetMaxByteCount(password.Length);
            var       key       = new byte[keylen];

            var pwBuffer = ArrayPool <byte> .Shared.Rent(pwMaxSize);

            var resultBuffer = ArrayPool <byte> .Shared.Rent(pwMaxSize + md5Length);

            try
            {
                var         pwLength = Encoding.UTF8.GetBytes(password, pwBuffer);
                var         pw       = pwBuffer.AsSpan(0, pwLength);
                Span <byte> md5Sum   = stackalloc byte[md5Length];
                var         result   = resultBuffer.AsSpan(0, pwLength + md5Length);
                var         i        = 0;
                while (i < keylen)
                {
                    if (i == 0)
                    {
                        MD5Utils.Default(pw, md5Sum);
                    }
                    else
                    {
                        md5Sum.CopyTo(result);
                        pw.CopyTo(result.Slice(md5Length));
                        MD5Utils.Default(result, md5Sum);
                    }

                    var length = Math.Min(16, keylen - i);
                    md5Sum.Slice(0, length).CopyTo(key.AsSpan(i, length));

                    i += md5Length;
                }
                return(key);
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(pwBuffer);

                ArrayPool <byte> .Shared.Return(resultBuffer);
            }
        }
Ejemplo n.º 4
0
        public void Default()
        {
            Span <byte> hash = stackalloc byte[HashConstants.Md5Length];

            MD5Utils.Default(_randombytes.Span, hash);
        }