/// <summary> /// DescriptorExists /// </summary> /// <param name="sercure_name"></param> /// <param name="store"></param> /// <param name="crypto"></param> /// <returns></returns> public static bool DescriptorExists(string sercure_name, IStorage store, CryptographyLib.ICryptography crypto) { string sub_dir_name = StoragePath.GetDirectory(sercure_name); string secure_sub_dir_name = SecureStorageUtility.GetSecureName(sub_dir_name, crypto.Key); return(store.Exists(secure_sub_dir_name)); }
/// <summary> /// CreateFile /// </summary> /// <param name="name">name of file</param> /// <param name="data">file data</param> public void CreateFile(string name, byte[] data) { // get all names string secure_name = GetSecureName(name); string dir_name = StoragePath.GetDirectory(name); string secure_dir_name = GetSecureName(dir_name); // encrypt file to upload byte[] encrypted_data = crypto.Encrypt(data); // upload file CreateAppendFragment(secure_name, encrypted_data); // create/append xml file node to xml directory node XmlDocument doc = GetDirectoryDocument(secure_dir_name); string hash = null; byte[] sha256 = SecureStorageUtility.SHA256(data); hash = Convert.ToBase64String(sha256); AppendFileXml(doc, name, hash); // delete old directory file Store.Delete(secure_dir_name); // create new directory file string xml = doc.OuterXml; data = Encoding.UTF8.GetBytes(xml); encrypted_data = crypto.Encrypt(data); Store.Create(secure_dir_name, encrypted_data, FileMode.Append); }
/// <summary> /// get a secure name /// </summary> /// <param name="name">orginal name</param> /// <returns>secure name based off original</returns> private string GetSecureName(string name) { byte[] hash = SecureStorageUtility.HMACSHA256(name, crypto.Key); return(SecureStorageUtility.FromBytesToHex(hash)); }
/// <summary> /// ReadFileSignatureXml /// </summary> /// <param name="doc"></param> /// <param name="name"></param> /// <returns></returns> private string ReadFileSignatureXml(XmlDocument doc, string name) { return(SecureStorageUtility.ReadFileSignatureXml(doc, name)); }
/// <summary> /// GetSecureHash /// </summary> /// <param name="data">data</param> /// <returns>string</returns> public string GetSecureHash(string data) { byte[] hash = SecureStorageUtility.HMACSHA256(data, Key); return(SecureStorageUtility.FromBytesToHex(hash)); }