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:
parent
f228758fb7
commit
4aa5ba2754
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user