public void HMACSHA256(string name, string secure_name) { byte[] hash = SecureStorageUtility.HMACSHA256(name, aes.Key); string actual = SecureStorageUtility.FromBytesToHex(hash); Assert.AreEqual(secure_name, actual); }
public void CreateEmpty(string name, int len, bool random = false) { byte[] data = null; if (random) { data = SecureStorageUtility.GererateKey(len); File.WriteAllBytes(working_dir + name, data); } else { data = new byte[len]; // are they not already zero? Array.Clear(data, 0, len); } }
public void CreateKeyLoadUse() { string unit_test_folder = Global.TestFolder + "CreateKeyLoadUse"; if (!Directory.Exists(unit_test_folder)) { Directory.CreateDirectory(Global.TestFolder + "CreateKeyLoadUse"); } string key_path = unit_test_folder + "\\key"; SecureStorageUtility.GererateWriteKey(unit_test_folder + "\\key", AES.DEFAULT_KEY_SIZE); SecureStorage store = new SecureStorage(new LocalStorage("test_tmp"), new AES(File.ReadAllBytes(key_path)), 1000); //BKP todo... //Assert.Fail(); // todo finish test case Assert.Inconclusive(); }
//private void btnInitialize_Click(object sender, EventArgs e) //{ // InitializeFrm dlg = new InitializeFrm(); // dlg.dirBrowser.TextBox.Text = Properties.Settings.Default.init_input_dir; // if (dlg.ShowDialog() == DialogResult.OK) // { // string output_dir = Properties.Settings.Default.server_mirror_dir; // //delete all file server directory // if (Directory.Exists(output_dir)) // Directory.Delete(output_dir, true); // Directory.CreateDirectory(output_dir); // // intitialize to server mirror dir // string initial_input_dir = dlg.dirBrowser.TextBox.Text; // SecureStorageUtility.InitializeLocalRoot(initial_input_dir, output_dir, key, iv); // // save setting for next time // Properties.Settings.Default.init_input_dir = initial_input_dir; // Properties.Settings.Default.Save(); // } // StdMsgBox.OK("InitializeLocalRoot Complete"); //} private void btnCreateKey_Click(object sender, EventArgs e) { string path = Properties.Settings.Default.key_loc.TrimEnd('\\'); if (!File.Exists(path)) { MessageBox.Show("Key path not found @ " + path, "check key_loc setting", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string keystore_loc = path + "\\keystore.tmp"; //BKP todo remove .tmp // old way, raw key, no keystore //SecureStorageUtility.GererateWriteKey(key_loc, 32); //StdMsgBox.OK("\"Key_new.tmp\" created."); byte[] key = SecureStorageUtility.GererateKey(32); KeyStore.CreateStore(keystore_loc, "abc", key); StdMsgBox.OK("\"keystore.tmp\" created."); }
public void CreateKeyStore() { string test_path = Global.TestFolder + "CreateKeyStore_key"; byte[] key1 = SecureStorageUtility.GererateKey(32); byte[] key2 = SecureStorageUtility.GererateKey(32); byte[] key3 = SecureStorageUtility.GererateKey(32); KeyStore.CreateStore(test_path, "abc", key1, key2, key3); KeyStore store = new KeyStore(test_path, "abc"); byte[] key11 = store[0]; byte[] key22 = store[1]; byte[] key33 = store[2]; CollectionAssert.AreEqual(key1, key11); CollectionAssert.AreNotEqual(key2, key11); CollectionAssert.AreEqual(key2, key22); CollectionAssert.AreNotEqual(key3, key22); CollectionAssert.AreEqual(key3, key33); }
public void GererateKey() { byte[] key = SecureStorageUtility.GererateKey(10); Assert.AreEqual(10, key.Length); }
/// <summary> /// get sha256 of file data /// </summary> /// <param name="name"></param> /// <returns></returns> public byte[] SHA256(string name) { byte[] data = File.ReadAllBytes(working_dir + name); return(SecureStorageUtility.SHA256(data)); }