private void ShouldReturnPublicKey() { var keyPair = EncryptorHelper.GenerateKeyPair(curve, algorithm); var publicKey = EncryptorHelper.GetPublicKey(keyPair); publicKey.Should().NotBeNull(); }
public virtual Option <EncryptedEntries> Process(Entries entries, HipLibrary.Patient.Model.KeyMaterial dataRequestKeyMaterial, string transactionId) { var keyPair = EncryptorHelper.GenerateKeyPair(dataRequestKeyMaterial.Curve, dataRequestKeyMaterial.CryptoAlg); var randomKey = EncryptorHelper.GenerateRandomKey(); var processedEntries = new List <Entry>(); var careBundles = entries.CareBundles; foreach (var careBundle in careBundles) { var encryptData = encryptor.EncryptData(dataRequestKeyMaterial, keyPair, Serializer.SerializeToString(careBundle.BundleForThisCcr), randomKey); if (!encryptData.HasValue) { return(Option.None <EncryptedEntries>()); } encryptData.MatchSome(content => { var entry = IsLinkable(content) ? StoreComponentAndGetLink(ComponentEntry(content, careBundle.CareContextReference), careBundle.CareContextReference) : ComponentEntry(content, careBundle.CareContextReference); processedEntries.Add(entry); }); } var keyStructure = new KeyStructure(DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), dataRequestKeyMaterial.DhPublicKey.Parameters, EncryptorHelper.GetPublicKey(keyPair)); var keyMaterial = new KeyMaterial(dataRequestKeyMaterial.CryptoAlg, dataRequestKeyMaterial.Curve, keyStructure, randomKey); return(Option.Some(new EncryptedEntries(processedEntries.AsEnumerable(), keyMaterial))); }