public async Task LoadNewPrivateKeyCorrectTest()
        {
            var ekey = new EncryptionKey("", "", true);
            await ekey.LoadNewKey(FakeDataGenerator.DefaultDto.BasicEncryptedMessage, "", true);

            var key = ekey.GetEncryptedKey(FakeDataGenerator.DefaultDto.BasicPassword);

            Assert.Equal(FakeDataGenerator.DefaultDto.BasicMessage, key);
        }
예제 #2
0
        public EncryptionKey Fill(EncryptionKey key)
        {
            if (key == null)
            {
                return(null);
            }

            try
            {
                key.Id = new Guid(Id);
            }
            catch (Exception ex)
            {
                log.Error("Node Guid stored in db is not valid, creating new one", ex);
                key.Id = new Guid();
            }

            try
            {
                key.RelatedItemId = new Guid(RelatedItemId);
            }
            catch (Exception ex)
            {
                log.Error("RelatedItemId Guid stored in db is not valid, creating new one", ex);
                key.RelatedItemId = new Guid();
            }

            key.IsEncrypted = (bool)IsEncrypted;
            key.Name        = Name;
            key.PublicKey   = PublicKey;
            key.Type        = (EncryptionKeyType)Type;
            key.Version     = Version;
            key.ModifiedOn  = ModifiedOn;
            key.ModifiedBy  = ModifiedBy;
            key.Deleted     = Deleted;
            key.CreatedBy   = CreatedBy;
            key.CreatedOn   = CreatedOn;

            if (PasswordHash?.Length > 0)
            {
                key.PasswordHash = PasswordHash;
            }

            if (!string.IsNullOrEmpty(StoredKey))
            {
                key.LoadNewKey(StoredKey, fromDb: true);
            }

            return(key);
        }