示例#1
0
        public WalletData Login()
        {
            Boolean passAccepted;

            if (WalletName == "")
            {
                Caller.SemaphoricExceptionCallLogin("No wallet name specified");
                return(null);
            }

            string WalletFilePath = AppDomain.CurrentDomain.BaseDirectory + @"bin\\WalletData\\" + WalletName + ".bin";

            if (!File.Exists(WalletFilePath) && MustCreateWallet)
            {
                if (PasswordManager.CheckPassRequirements(passString))
                {
                    WalletDataLocal = GenerateWallet.NewWallet(WalletName, WalletFilePath, passString);
                    Caller.SemaphoricExceptionCallLogin("Wallet created!");
                    return(WalletDataLocal);
                }
                else
                {
                    Caller.SemaphoricExceptionCallLogin("Passcode does not comply with requirements !");
                    return(null);
                }
            }
            else if (File.Exists(WalletFilePath) && MustCreateWallet)
            {
                Caller.SemaphoricExceptionCallLogin("Wallet already exists!");
                return(null);
            }
            else if (!File.Exists(WalletFilePath))
            {
                Caller.SemaphoricExceptionCallLogin("Wallet does not exist");
                return(null);
            }
            else
            {
                WalletDataLocal = WalletData.ReadBlobToWalletData(WalletName);

                //Checking passWord
                passAccepted = PasswordManager.CheckPass(passString, Convert.ToBase64String(WalletDataLocal.passCode));

                passString = "";    //Dispose of the pass, we don't want any traces left

                if (!passAccepted)
                {
                    System.Threading.Thread.Sleep(1 * 1000);
                    Caller.SemaphoricExceptionCallLogin("Wrong passcode entered!");
                    return(null);
                }

                return(WalletDataLocal);
            }
        }
        public static void WriteWalletData(WalletData _WalletDataToBlob, string _walletName)
        {
            //TODO: Move serialization to FileBinIO to avoid duplicating code on multiple objects
            MemoryStream    memorystream = new MemoryStream();
            BinaryFormatter bf           = new BinaryFormatter();

            bf.Serialize(memorystream, _WalletDataToBlob);
            byte[] BlobData = memorystream.ToArray();

            FileBinIO.WriteBin(BlobData, _walletName);
        }
        public WalletData CreateNewWalletData(Keys _Keys, string _pass, string _walletName)
        {
            WalletData WalletDataLocal = new WalletData();

            WalletDataLocal.Keydata    = _Keys;
            WalletDataLocal.passCode   = PasswordManager.GenerateSaltedOutputBytes(_pass);
            WalletDataLocal.walletName = _walletName;
            //Now we got the object filled, store its data

            WalletData.WriteWalletData(WalletDataLocal, _walletName);

            return(WalletDataLocal);
        }
        public static WalletData ReadBlobToWalletData(string _walletName)
        {
            //Read from bin
            //TODO: Move deserialization to FileBinIO to avoid duplicating code on multiple objects
            byte[] BlobData = FileBinIO.ReadBin(AppDomain.CurrentDomain.BaseDirectory + @"bin\\WalletData\\" + _walletName + ".bin");

            MemoryStream    memorystreamd     = new MemoryStream(BlobData);
            BinaryFormatter bfd               = new BinaryFormatter();
            WalletData      deserializedBlock = bfd.Deserialize(memorystreamd) as WalletData;

            memorystreamd.Close();

            return(deserializedBlock);
        }
        //this class will hold all required code for creating a new wallet from scratch

        public static WalletData NewWallet(String _walletName, String _walletfilePath, string _passCode)
        {
            String     passString = _passCode;
            Keys       KeysClass;
            Boolean    passAcceptable;
            WalletData WalletDataCreate;

            passAcceptable = PasswordManager.CheckPassRequirements(passString);

            if (passAcceptable)
            {
                KeysClass        = KeyManager.GenerateKeySet(_passCode, _walletName);
                WalletDataCreate = new WalletData();
                WalletDataCreate = WalletDataCreate.CreateNewWalletData(KeysClass, _passCode, _walletName);

                return(WalletDataCreate);
            }
            else
            {
                return(null);
            }
        }
        public WalletData   ParmWalletData(WalletData _Data)
        {
            wData = _Data;

            return(wData);
        }