public void sendFile(IRimRecords records, String filename) { logger.LogStatus("Sending file " + filename + " to device"); setProgress("Sending database"); IRimRecord r = records.AddRecord(); r.RecordID = RECORD_DATABASE; r.Version = 4; IRimField f = r.fields.AddField(); f.Id = FIELD_RECORD_TYPE; f.value = RECORD_DATABASE; FileInfo fi = new FileInfo(filename); FileStream fs = File.Open(filename, FileMode.Open); BinaryReader br = new BinaryReader(fs); int l = (int)fi.Length; while (l > 0) { byte[] buffer = br.ReadBytes(Math.Min(l, 8192)); f = r.fields.AddField(); f.Id = FIELD_TYPE_DATA; f.value = buffer; l -= buffer.Length; /* SHA256 md = new SHA256Managed(); byte[] hash = md.ComputeHash(buffer); f = r.fields.AddField(); f.Id = FIELD_TYPE_CHECKSUM; f.value = hash; * */ } br.Close(); fs.Close(); r.Update(); }
public void sendCredentials(IRimRecords records) { logger.LogStatus("Sending credentials."); setProgress("Sending credentials"); IRimRecord r = records.AddRecord(); r.RecordID = RECORD_CREDENTIALS; r.Version = 4; IRimField f = r.fields.AddField(); f.Id = FIELD_RECORD_TYPE; f.value = RECORD_CREDENTIALS; if (password != null && password.Length > 0) { f = r.fields.AddField(); f.Id = FIELD_PASSWORD; byte[] pba = new byte[password.Length]; for (int i = 0; i < pba.Length; i++) pba[i] = (byte)password[i]; f.value = pba; } if (keyfile != null && keyfile.Length > 0) { FileInfo fi = new FileInfo(keyfile); FileStream fs = File.Open(keyfile, FileMode.Open); BinaryReader br = new BinaryReader(fs); int l = (int)fi.Length; while (l > 0) { byte[] buffer = br.ReadBytes(Math.Min(l, 8192)); f = r.fields.AddField(); f.Id = FIELD_KEYFILE; f.value = buffer; l -= buffer.Length; } br.Close(); fs.Close(); } r.Update(); }