Exemplo n.º 1
0
        /// <summary>
        /// Decode the username from filename
        /// </summary>
        /// <param name="fileName">File name used to decode username</param>
        /// <param name="fileType">File type</param>
        /// <returns>decoded username</returns>
        public static string GetUserNameFromFileName(string fileName, PxFileType fileType = PxFileType.PxData)
        {
            string trimedName = null;
            string head       = PxFileTypeInfo.GetHead(fileType);
            string tail       = PxFileTypeInfo.GetTail(fileType);

            // If it is an file exported from PassXYZ, we can decode the user name.
            if (fileName.StartsWith(head))
            {
                trimedName = fileName.Substring(head.Length);
                trimedName = trimedName.Substring(0, trimedName.LastIndexOf(tail));
                //Debug.WriteLine($"GetUserNameFromFileName: {fileName}, {trimedName}");
            }
            else
            {
                Debug.WriteLine($"GetUserNameFromFileName: {fileName} is not PassXYZ data file.");
                return(string.Empty);
            }

            try
            {
                if (trimedName != string.Empty)
                {
                    trimedName = Base58CheckEncoding.GetString(trimedName);
                }
            }
            catch (FormatException e)
            {
                Debug.WriteLine($"GetUserNameFromFileName decode failed with {e.Message}");
                trimedName = string.Empty;
            }

            return(trimedName);
        }
Exemplo n.º 2
0
        public static string GetTail(PxFileType fileType)
        {
            string strHead = null;

            switch (fileType)
            {
            case PxFileType.PwData:
                strHead = PxDefs.kdbx;
                break;

            case PxFileType.PxData:
            case PxFileType.PxDataEx:
                strHead = PxDefs.xyz;
                break;

            case PxFileType.PxKeyFile:
                strHead = PxDefs.k4xyz;
                break;

            case PxFileType.PxSync:
                strHead = PxDefs.r4xyz;
                break;

            case PxFileType.PxExchange:
                strHead = PxDefs.s4xyz;
                break;

            case PxFileType.PxTemplate:
                strHead = PxDefs.t4xyz;
                break;

            default:
                break;
            }
            return(strHead);
        }
Exemplo n.º 3
0
        public static string GetHead(PxFileType fileType)
        {
            string strHead = null;

            switch (fileType)
            {
            case PxFileType.PwData:
            case PxFileType.PxData:
                strHead = PxDefs.head_xyz;
                break;

            case PxFileType.PxDataEx:
                strHead = PxDefs.head_data;
                break;

            case PxFileType.PxKeyFile:
                strHead = PxDefs.head_k4xyz;
                break;

            case PxFileType.PxSync:
                strHead = PxDefs.head_r4xyz;
                break;

            case PxFileType.PxExchange:
                strHead = PxDefs.head_s4xyz;
                break;

            case PxFileType.PxTemplate:
                strHead = PxDefs.head_t4xyz;
                break;

            default:
                break;
            }
            return(strHead);
        }