1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-17 15:27:43 +01:00

use crypto service

This commit is contained in:
Kyle Spearrin 2019-04-15 07:56:46 -04:00
parent f228758fb7
commit 4aa5ba2754
2 changed files with 36 additions and 10 deletions

View File

@ -1,5 +1,7 @@
using Bit.Core.Models.Data;
using Bit.Core.Abstractions;
using Bit.Core.Models.Data;
using Bit.Core.Models.View;
using Bit.Core.Utilities;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -38,8 +40,20 @@ namespace Bit.Core.Models.Domain
"FileName"
}, orgId);
// TODO: Decrypt key
if(Key != null)
{
var cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
try
{
var orgKey = await cryptoService.GetOrgKeyAsync(orgId);
var decValue = await cryptoService.DecryptToBytesAsync(Key, orgKey);
view.Key = new SymmetricCryptoKey(decValue);
}
catch
{
// TODO: error?
}
}
return view;
}

View File

@ -1,4 +1,6 @@
using Bit.Core.Enums;
using Bit.Core.Abstractions;
using Bit.Core.Enums;
using Bit.Core.Utilities;
using System;
using System.Threading.Tasks;
@ -97,14 +99,24 @@ namespace Bit.Core.Models.Domain
public string Data { get; private set; }
public string Mac { get; private set; }
public Task<string> DecryptAsync(string orgId = null)
public async Task<string> DecryptAsync(string orgId = null)
{
if(_decryptedValue == null)
if(_decryptedValue != null)
{
// TODO
return _decryptedValue;
}
return Task.FromResult(_decryptedValue);
var cryptoService = ServiceContainer.Resolve<ICryptoService>("cryptoService");
try
{
var orgKey = await cryptoService.GetOrgKeyAsync(orgId);
_decryptedValue = await cryptoService.DecryptToUtf8Async(this, orgKey);
}
catch
{
_decryptedValue = "[error: cannot decrypt]";
}
return _decryptedValue;
}
}
}