コード例 #1
0
ファイル: Pbkdf2Result.cs プロジェクト: tforcexyz/tfxlib
 public Pbkdf2Result(byte[] password, byte[] salt, int iteration, byte[] key)
 {
     Password  = BytesEx.FromBytes(password);
     Salt      = BytesEx.FromBytes(salt);
     Iteration = iteration;
     Key       = BytesEx.FromBytes(key);
 }
コード例 #2
0
ファイル: Pbkdf2Result.cs プロジェクト: tforcexyz/tfxlib
 public Pbkdf2Result(BytesEx password, BytesEx salt, int iteration, BytesEx key)
 {
     Password  = password;
     Salt      = salt;
     Iteration = iteration;
     Key       = key;
 }
コード例 #3
0
ファイル: HashExpress.cs プロジェクト: tforcexyz/tfxlib
        public static BytesEx Hash(BytesEx input, HashAlgorithm algorithm)
        {
            System.Security.Cryptography.HashAlgorithm hasher = GetAlgorithm(algorithm);
            byte[]  hashByte = hasher.ComputeHash(input.Values);
            BytesEx hash     = BytesEx.FromBytes(hashByte);

            return(hash);
        }
コード例 #4
0
ファイル: FileDescriptor.cs プロジェクト: tforcexyz/tfxlib
 internal FileDescriptor(string name, string extension, string parent, FileMetadata property = null, BytesEx md5 = null, BytesEx sha1 = null, BytesEx sha256 = null, BytesEx sha512 = null)
     : base(name, extension, parent)
 {
     Property = property;
     Md5      = md5;
     Sha1     = sha1;
     Sha256   = sha256;
     Sha512   = sha512;
 }
コード例 #5
0
ファイル: Pbkdf2Crypt.cs プロジェクト: tforcexyz/tfxlib
        public static bool Verify(string password, byte[] salt, int iteration, byte[] key)
        {
            BytesEx      passwordBytes = BytesEx.FromString(password);
            BytesEx      saltBytes     = BytesEx.FromBytes(salt);
            BytesEx      keyBytes      = BytesEx.FromBytes(key);
            Pbkdf2Result pbkdf2        = new Pbkdf2Result(passwordBytes, saltBytes, iteration, keyBytes);

            return(Verify(pbkdf2));
        }
コード例 #6
0
ファイル: Pbkdf2Crypt.cs プロジェクト: tforcexyz/tfxlib
        public static Pbkdf2Result Hash(string password, int?saltLength, int?iteration, int?keyLength)
        {
            Pbkdf2Parameter parameter = new Pbkdf2Parameter();

            parameter.Password   = BytesEx.FromString(password);
            parameter.SaltLength = saltLength;
            parameter.Iteration  = iteration;
            parameter.KeyLength  = keyLength;
            Pbkdf2Result pbkdf2 = Hash(parameter);

            return(pbkdf2);
        }
コード例 #7
0
ファイル: HashExpress.cs プロジェクト: tforcexyz/tfxlib
        public static BytesEx Sha256(BytesEx input)
        {
            BytesEx hash = Hash(input, HashAlgorithm.Sha256);

            return(hash);
        }
コード例 #8
0
ファイル: HashExpress.cs プロジェクト: tforcexyz/tfxlib
        public static BytesEx Md5(BytesEx input)
        {
            BytesEx hash = Hash(input, HashAlgorithm.Md5);

            return(hash);
        }
コード例 #9
0
        internal static FileDescriptor GetFileDescriptor(FileGetFileDescriptorArgument args)
        {
            string       realPath   = PathExpress.ResolvePath(args.Path);
            string       parent     = Path.GetDirectoryName(realPath);
            string       fullName   = Path.GetFileName(realPath);
            string       name       = Path.GetFileNameWithoutExtension(fullName);
            string       extension  = Path.GetExtension(fullName);
            FileMetadata metadata   = null;
            BytesEx      md5Hash    = null;
            BytesEx      sha1Hash   = null;
            BytesEx      sha256Hash = null;
            BytesEx      sha512Hash = null;

            if (args.IncludeAttribute)
            {
                FileInfo fileInfo     = new FileInfo(realPath);
                bool     isArchive    = fileInfo.Attributes.HasFlag(FileAttributes.Archive);
                bool     isReadOnly   = fileInfo.Attributes.HasFlag(FileAttributes.ReadOnly);
                bool     isHidden     = fileInfo.Attributes.HasFlag(FileAttributes.Hidden);
                bool     isSystem     = fileInfo.Attributes.HasFlag(FileAttributes.System);
                long     length       = fileInfo.Length;
                DateTime createdTime  = fileInfo.CreationTimeUtc;
                DateTime modifiedTime = fileInfo.LastWriteTimeUtc;
                DateTime accessTime   = fileInfo.LastAccessTimeUtc;
                metadata = new FileMetadata(isArchive, isHidden, isReadOnly, isSystem, length, createdTime, accessTime, modifiedTime);
            }
            if (args.IncludeMd5 || args.IncludeSha1 || args.IncludeSha256 || args.IncludeSha512)
            {
                string md5    = "md5";
                string sha1   = "sha1";
                string sha256 = "sha256";
                string sha512 = "sha512";
                Dictionary <string, System.Security.Cryptography.HashAlgorithm> cryptDictionary = new Dictionary <string, System.Security.Cryptography.HashAlgorithm>();
                if (args.IncludeMd5)
                {
                    cryptDictionary[md5] = HashExpress.GetAlgorithm(HashAlgorithm.Md5);
                }
                if (args.IncludeSha1)
                {
                    cryptDictionary[sha1] = HashExpress.GetAlgorithm(HashAlgorithm.Sha1);
                }
                if (args.IncludeSha256)
                {
                    cryptDictionary[sha256] = HashExpress.GetAlgorithm(HashAlgorithm.Sha256);
                }
                if (args.IncludeSha512)
                {
                    cryptDictionary[sha512] = HashExpress.GetAlgorithm(HashAlgorithm.Sha512);
                }
                System.Security.Cryptography.HashAlgorithm[] crypts = cryptDictionary.Values.ToArray();
                using (Stream fileStream = new FileStream(realPath, FileMode.Open))
                {
                    byte[] buffer = new byte[HashExpress.StreamBufferSize];
                    int    read;
                    long   currentPosition = 0L;
                    long   streamLength    = fileStream.Length;
                    while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        currentPosition += read;
                        foreach (System.Security.Cryptography.HashAlgorithm crypt in crypts)
                        {
                            if (currentPosition < streamLength)
                            {
                                int _ = crypt.TransformBlock(buffer, 0, read, buffer, 0);
                            }
                            else
                            {
                                byte[] _ = crypt.TransformFinalBlock(buffer, 0, read);
                            }
                        }
                    }
                    if (args.IncludeMd5)
                    {
                        md5Hash = BytesEx.FromBytes(cryptDictionary[md5].Hash);
                    }
                    if (args.IncludeSha1)
                    {
                        sha1Hash = BytesEx.FromBytes(cryptDictionary[sha1].Hash);
                    }
                    if (args.IncludeSha256)
                    {
                        sha256Hash = BytesEx.FromBytes(cryptDictionary[sha256].Hash);
                    }
                    if (args.IncludeSha512)
                    {
                        sha512Hash = BytesEx.FromBytes(cryptDictionary[sha512].Hash);
                    }
                }
            }
            FileDescriptor result = new FileDescriptor(name, extension, parent, metadata, md5Hash, sha1Hash, sha256Hash, sha512Hash);

            return(result);
        }