Esempio n. 1
0
        ///--------------------------------------------------------------------------------------------------------
        ///
        public bool SetPassword(string pwd)
        {
            string hdmasterkeyid = QtumHandler.GetHDMasterKeyId();

            if (string.IsNullOrEmpty(hdmasterkeyid))
            {
                Logger.Log("퀀텀 지갑의 구동 상태를 확인 해 주세요.");
                return(false);
            }

            try
            {
                byte[] pwdBytes = Encoding.UTF8.GetBytes(Encrypt(pwd, Encrypt(hdmasterkeyid, Config.RPCPassword)));

                using (FileStream fs = File.Open(passwordFile, FileMode.Create))
                {
                    using (GZipOutputStream gzs = new GZipOutputStream(fs))
                    {
                        using (MemoryStream c = new MemoryStream())
                        {
                            gzs.Write(pwdBytes, 0, pwdBytes.Length);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        ///--------------------------------------------------------------------------------------------------------
        ///
        public string GetPassword()
        {
            string pwd = null;

            string hdmasterkeyid = QtumHandler.GetHDMasterKeyId();

            if (string.IsNullOrEmpty(hdmasterkeyid))
            {
                Logger.Log("퀀텀 지갑의 구동 상태를 확인 해 주세요.");
                return(pwd);
            }

            try
            {
                if (File.Exists(passwordFile) == false)
                {
                    Logger.Log("파일 없음 : {0}", passwordFile);
                    return(pwd);
                }

                using (FileStream fs = File.Open(passwordFile, FileMode.Open))
                {
                    using (GZipInputStream gzs = new GZipInputStream(fs))
                    {
                        const int count  = 1024 * 1024;
                        byte[]    dest   = new byte[count];
                        int       length = gzs.Read(dest, 0, count);

                        pwd = Decrypt(Encoding.UTF8.GetString(dest, 0, length), Encrypt(hdmasterkeyid, Config.RPCPassword));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
                return(null);
            }

            return(pwd);
        }