key names

This commit is contained in:
Kyle Spearrin 2017-05-27 11:46:42 -04:00
parent 8450f56093
commit 72f9951cb1

View file

@ -24,7 +24,7 @@ namespace Bit.Android.Services
private const string SettingsFormat = "ksSecured:{0}"; private const string SettingsFormat = "ksSecured:{0}";
private const string RsaMode = "RSA/ECB/PKCS1Padding"; private const string RsaMode = "RSA/ECB/PKCS1Padding";
private const string AesMode = "AES/GCM/NoPadding"; private const string AesMode = "AES/GCM/NoPadding";
private const string EncryptedKey = "ksSecuredAesKey"; private const string AesKey = "ksSecured:aesKeyForService";
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly KeyStore _keyStore; private readonly KeyStore _keyStore;
@ -131,21 +131,21 @@ namespace Bit.Android.Services
return; return;
} }
if(_settings.Contains(EncryptedKey)) if(_settings.Contains(AesKey))
{ {
return; return;
} }
var key = RandomBytes(16); var key = RandomBytes(16);
var encKey = RsaEncrypt(key); var encKey = RsaEncrypt(key);
_settings.AddOrUpdateValue(EncryptedKey, Convert.ToBase64String(encKey)); _settings.AddOrUpdateValue(AesKey, Convert.ToBase64String(encKey));
} }
private IKey GetAesKey() private IKey GetAesKey()
{ {
if(_oldAndroid) if(_oldAndroid)
{ {
var encKey = _settings.GetValueOrDefault<string>(EncryptedKey); var encKey = _settings.GetValueOrDefault<string>(AesKey);
var encKeyBytes = Convert.FromBase64String(encKey); var encKeyBytes = Convert.FromBase64String(encKey);
var key = RsaDecrypt(encKeyBytes); var key = RsaDecrypt(encKeyBytes);
return new SecretKeySpec(key, "AES"); return new SecretKeySpec(key, "AES");