Esempio n. 1
0
        public void loadFiles()
        {
            try
            {
                FileStream   fileStream = new FileStream(SECURE_KEY_STORAGE_NAME, FileMode.Open);
                BinaryReader reader     = new BinaryReader(fileStream, Encoding.Default);
                String       buffer     = reader.ReadString();
                String       decrypted  = StringSecure.decodeBase64(buffer);
                reader.Close();
                fileStream.Close();
                Utils.log("Secure Key loaded!");
                SecureKeyPair loadedSecureKey = JsonConvert.DeserializeObject <SecureKeyPair>(decrypted);
                this.stringSecure = new StringSecure(loadedSecureKey);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            try
            {
                FileStream   fileStream = new FileStream(getEncodedDatafileName(), FileMode.Open);
                BinaryReader reader     = new BinaryReader(fileStream, Encoding.Default);
                String       buffer     = reader.ReadString();
                String       decrypted  = buffer;
                reader.Close();
                fileStream.Close();
                Utils.log("Data loaded!");
                datafile = JsonConvert.DeserializeObject <EncryptedDatafile>(decrypted);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 2
0
        private void finallyCheckPassword(object sender, RoutedEventArgs e)
        {
            String inputPW = StringSecure.encodeSHA256(importedFilePassword.Password);

            if (!inputPW.Equals(importedPW))
            {
                MessageBox.Show("비밀번호가 일치하지 않습니다!", "비밀번호 불일치");
                importedFilePassword.Password = "";
                return;
            }
            this.DialogResult = true;
            this.Close();
            return;
        }
Esempio n. 3
0
 public DatafileManager()
 {
     if (File.Exists(getEncodedDatafileName()))
     {
         //파일 존재함, 이후에 유효한지 검사
         loadFiles();
     }
     else
     {
         //파일 없음, 생성
         SecureKeyPair secureKeyPair = new SecureKeyPair();
         stringSecure = new StringSecure(secureKeyPair);
         datafile     = new EncryptedDatafile(stringSecure);
         saveSecureKeyFile(secureKeyPair);
     }
 }
Esempio n. 4
0
 public void saveSecureKeyFile(SecureKeyPair secureKeyPair)
 {
     try
     {
         FileStream   fileStream = new FileStream(SECURE_KEY_STORAGE_NAME, FileMode.Create);
         BinaryWriter writer     = new BinaryWriter(fileStream, Encoding.Default);
         String       buffer     = JsonConvert.SerializeObject(secureKeyPair, Formatting.Indented);
         writer.Write(StringSecure.encodeBase64(buffer));
         writer.Close();
         fileStream.Close();
         Utils.log("Secure Key saved to " + SECURE_KEY_STORAGE_NAME);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }