1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-03 08:39:46 +01:00

RSA/ECB/OAEPWithSHA-1AndMGF1Padding

This commit is contained in:
Kyle Spearrin 2017-06-06 23:52:52 -04:00
parent 1503124108
commit 724ae51110

View File

@ -32,7 +32,7 @@ namespace Bit.Android.Services
public KeyStoreBackedStorageService(ISettings settings) public KeyStoreBackedStorageService(ISettings settings)
{ {
_oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M; _oldAndroid = Build.VERSION.SdkInt < BuildVersionCodes.M;
_rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPPadding"; _rsaMode = _oldAndroid ? "RSA/ECB/PKCS1Padding" : "RSA/ECB/OAEPWithSHA-1AndMGF1Padding";
_oldKeyStorageService = new KeyStoreStorageService(new char[] { }); _oldKeyStorageService = new KeyStoreStorageService(new char[] { });
_settings = settings; _settings = settings;
@ -146,10 +146,6 @@ namespace Bit.Android.Services
else else
{ {
var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt) var spec = new KeyGenParameterSpec.Builder(KeyAlias, KeyStorePurpose.Decrypt | KeyStorePurpose.Encrypt)
.SetCertificateSubject(subject)
.SetCertificateSerialNumber(BigInteger.Ten)
.SetKeyValidityStart(start.Time)
.SetKeyValidityEnd(end.Time)
.SetDigests(KeyProperties.DigestSha1) .SetDigests(KeyProperties.DigestSha1)
.SetEncryptionPaddings(KeyProperties.EncryptionPaddingRsaOaep) .SetEncryptionPaddings(KeyProperties.EncryptionPaddingRsaOaep)
.Build(); .Build();
@ -216,7 +212,7 @@ namespace Bit.Android.Services
private byte[] RsaDecrypt(byte[] encData) private byte[] RsaDecrypt(byte[] encData)
{ {
using(var entry = GetRsaKeyEntry()) using(var entry = GetRsaKeyEntry())
using(var cipher = Cipher.GetInstance(_rsaMode, "AndroidKeyStoreBCWorkaround")) using(var cipher = Cipher.GetInstance(_rsaMode))
{ {
cipher.Init(CipherMode.DecryptMode, entry.PrivateKey, OAEPParameterSpec.Default); cipher.Init(CipherMode.DecryptMode, entry.PrivateKey, OAEPParameterSpec.Default);
var plainText = cipher.DoFinal(encData); var plainText = cipher.DoFinal(encData);