namespace Common.UI.Models { using SQLite; internal class RadioKey { [PrimaryKey] [AutoIncrement] public int Id { get; set; } public uint Address { get; set; } public string EncryptionKey { get; set; } } internal class SQLiteKeyStore { private readonly SQLiteConnection connection; public SQLiteKeyStore() { this.connection = new SQLiteConnection(new SQLiteConnectionString("keystore.db")); _ = this.connection.CreateTable(); } public bool TryGetKey(uint address1, uint address2, out string encryptionKey) { //var existing = this.connection // .Table() // .Where(x => x.Address == 4291535650) // .FirstOrDefault(); //if (existing != null) //{ // existing.EncryptionKey = "5DD3EF5233B4DAA6836721F2866182DA"; // this.connection.Update(existing); //} encryptionKey = this.connection .Table() .FirstOrDefault(x => x.Address == address1 || x.Address == address2) ?.EncryptionKey; return !string.IsNullOrWhiteSpace(encryptionKey); } public void AddKey(uint address1, uint address2, string encryptionKey) { this.connection.Insert(new RadioKey { Address = address1, EncryptionKey = encryptionKey }); this.connection.Insert(new RadioKey { Address = address2, EncryptionKey = encryptionKey }); } } }