Exemplo n.º 1
0
        private void ShouldReturnPublicKey()
        {
            var keyPair   = EncryptorHelper.GenerateKeyPair(curve, algorithm);
            var publicKey = EncryptorHelper.GetPublicKey(keyPair);

            publicKey.Should().NotBeNull();
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
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 ShouldGenerateGenerateKeyPair()
        {
            var keyPair = EncryptorHelper.GenerateKeyPair("curve25519", "ECDH");

            keyPair.Should().NotBeNull();
        }
Exemplo n.º 5
0
        private void ShouldGenerateKeyPair()
        {
            var keyPair = EncryptorHelper.GenerateKeyPair(curve, algorithm);

            keyPair.Should().NotBeNull();
        }