public LedgerEntry <TrsanctioneeIdType> Decrypt <TrsanctioneeIdType>(EncryptedLedgerEntry <TrsanctioneeIdType> ledgerEntry, out bool verificationFlag) { LedgerEntry <TrsanctioneeIdType> decrypt = new LedgerEntry <TrsanctioneeIdType>(); var type = typeof(EncryptedLedgerEntry <TrsanctioneeIdType>); string signature = ""; foreach (var property in type.GetProperties().Where(x => x.Name != "TransactioneeId")) { if (property.Name == "Signature") { signature = property.GetValue(ledgerEntry).ToString(); } else if (property.Name != "PrimaryKey") { var value = Decrypt(property.GetValue(ledgerEntry).ToString()); var name = property.Name; foreach (var item in typeof(LedgerEntry <TrsanctioneeIdType>).GetProperties()) { if (item.Name == name) { item.SetValue(decrypt, Convert.ChangeType(value, item.PropertyType)); break; } } } else { decrypt.PrimaryKey = Convert.ToInt64(ledgerEntry.PrimaryKey); } } decrypt.TransactioneeId = ledgerEntry.TransactioneeId; verificationFlag = digitalSigning.VerifySignature(decrypt, signature); return(decrypt); }
public EncryptedLedgerEntry <TrsanctioneeIdType> Encrypt <TrsanctioneeIdType>(LedgerEntry <TrsanctioneeIdType> ledgerEntry) { EncryptedLedgerEntry <TrsanctioneeIdType> encrypted = new EncryptedLedgerEntry <TrsanctioneeIdType>(); var type = typeof(LedgerEntry <TrsanctioneeIdType>); foreach (var property in type.GetProperties().Where(x => x.Name != "TransactioneeId")) { if (property.Name != "PrimaryKey") { var cipher = Encrypt(property.GetValue(ledgerEntry).ToString()); var name = property.Name; typeof(EncryptedLedgerEntry <TrsanctioneeIdType>).GetProperties() .Where(x => x.Name == name) .FirstOrDefault() .SetValue(encrypted, cipher); } else { encrypted.PrimaryKey = ledgerEntry.PrimaryKey; } } encrypted.TransactioneeId = ledgerEntry.TransactioneeId; encrypted.Signature = digitalSigning.GetSignature(ledgerEntry); return(encrypted); }
public long CreateEntry(EncryptedLedgerEntry <int> ledgerEntry) { var table = Map(ledgerEntry); var result = DbContext .Table .Add(table) .Entity .Id; DbContext.SaveChanges(); return(result); }
private Table Map(EncryptedLedgerEntry <int> ledgerEntry) { var table = new Table(); foreach (var prop in typeof(Table).GetProperties()) { try { var ledgerProp = typeof(EncryptedLedgerEntry <int>) .GetProperties() .Where(x => x.Name == prop.Name) .Single(); prop.SetValue(table, Convert.ChangeType(ledgerProp.GetValue(ledgerEntry), ledgerProp.PropertyType)); } catch (InvalidOperationException) { } } table.Id = ledgerEntry.PrimaryKey; return(table); }
private EncryptedLedgerEntry <int> Map(Table table) { var ledgerEntry = new EncryptedLedgerEntry <int>(); foreach (var prop in typeof(EncryptedLedgerEntry <int>).GetProperties()) { try { var ledgerProp = typeof(Table) .GetProperties() .Where(x => x.Name == prop.Name) .Single(); prop.SetValue(ledgerEntry, Convert.ChangeType(ledgerProp.GetValue(table), prop.PropertyType)); } catch (InvalidOperationException) { } } ledgerEntry.PrimaryKey = table.Id; return(ledgerEntry); }
public bool VerifyEntry(EncryptedLedgerEntry <TransactioneeId> encryptedLedgerEntry) { cryptography.Decrypt <TransactioneeId>(encryptedLedgerEntry, out bool result); return(result); }