mirror of
https://github.com/bitwarden/android.git
synced 2024-12-26 10:58:29 +03:00
use crypto service
This commit is contained in:
parent
f228758fb7
commit
4aa5ba2754
2 changed files with 36 additions and 10 deletions
|
@ -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.Models.View;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -38,8 +40,20 @@ namespace Bit.Core.Models.Domain
|
||||||
"FileName"
|
"FileName"
|
||||||
}, orgId);
|
}, 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;
|
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;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -97,14 +99,24 @@ namespace Bit.Core.Models.Domain
|
||||||
public string Data { get; private set; }
|
public string Data { get; private set; }
|
||||||
public string Mac { 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 a new issue