private void ShouldGenerate32ByteRandomKey() { var randomKey = EncryptorHelper.GenerateRandomKey(); var randomKeyByte = GetByteFromBase64(randomKey); randomKeyByte.Count().Should().Be(32); }
private void ShouldGenerate32ByteXor() { var randomKey1 = EncryptorHelper.GenerateRandomKey(); var randomKey2 = EncryptorHelper.GenerateRandomKey(); var xorRandom = EncryptorHelper.XorOfRandom(randomKey1, randomKey2); xorRandom.Count().Should().Be(32); }
private void ShouldNotEncryptData() { var randomKeyFirst = EncryptorHelper.GenerateRandomKey(); var randomKeySecond = EncryptorHelper.GenerateRandomKey(); var senderKeyPair = EncryptorHelper.GenerateKeyPair(curve, algorithm); const string receiverPublicKey = "BE7rHCAB0xdU/wTh4PeZhnmLfPSS2CQQo3Loi2D3sWiGBwm9lwsxudMgTyjZ0KUzEqUniuW7zmDr3Vy9JeYI7gA="; var keyMaterial = new KeyMaterial(algorithm, curve, new KeyStructure("", "", receiverPublicKey), randomKeyFirst); var result = encryptor.EncryptData(keyMaterial, senderKeyPair, null, randomKeySecond); result.HasValue.Should().BeFalse(); result.MatchSome(data => data.Length.Should().Be(0)); }
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))); }
private void ShouldReturn34ByteRandomKey() { var randomKey = EncryptorHelper.GetByteFromBase64(EncryptorHelper.GenerateRandomKey()); randomKey.Count().Should().Be(32); }