mirror of
https://github.com/bitwarden/mobile
synced 2026-02-22 12:23:30 +00:00
crypto function service
This commit is contained in:
@@ -49,6 +49,9 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Portable.BouncyCastle">
|
||||
<Version>1.8.5</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Xamarin.Essentials">
|
||||
<Version>1.1.0</Version>
|
||||
</PackageReference>
|
||||
@@ -64,6 +67,7 @@
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\CryptoPrimitiveService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidAsset Include="Assets\FontAwesome.ttf" />
|
||||
|
||||
16
src/Android/Resources/Resource.designer.cs
generated
16
src/Android/Resources/Resource.designer.cs
generated
@@ -26,6 +26,8 @@ namespace Bit.Droid
|
||||
|
||||
public static void UpdateIdValues()
|
||||
{
|
||||
global::PCLCrypto.Resource.String.ApplicationName = global::Bit.Droid.Resource.String.ApplicationName;
|
||||
global::PCLCrypto.Resource.String.Hello = global::Bit.Droid.Resource.String.Hello;
|
||||
global::Xamarin.Essentials.Resource.Attribute.alpha = global::Bit.Droid.Resource.Attribute.alpha;
|
||||
global::Xamarin.Essentials.Resource.Attribute.coordinatorLayoutStyle = global::Bit.Droid.Resource.Attribute.coordinatorLayoutStyle;
|
||||
global::Xamarin.Essentials.Resource.Attribute.font = global::Bit.Droid.Resource.Attribute.font;
|
||||
@@ -7693,13 +7695,19 @@ namespace Bit.Droid
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f0b004f
|
||||
public const int AutoFillServiceDescription = 2131427407;
|
||||
public const int ApplicationName = 2131427407;
|
||||
|
||||
// aapt resource value: 0x7f0b004e
|
||||
public const int AutoFillServiceSummary = 2131427406;
|
||||
// aapt resource value: 0x7f0b0051
|
||||
public const int AutoFillServiceDescription = 2131427409;
|
||||
|
||||
// aapt resource value: 0x7f0b0050
|
||||
public const int MyVault = 2131427408;
|
||||
public const int AutoFillServiceSummary = 2131427408;
|
||||
|
||||
// aapt resource value: 0x7f0b004e
|
||||
public const int Hello = 2131427406;
|
||||
|
||||
// aapt resource value: 0x7f0b0052
|
||||
public const int MyVault = 2131427410;
|
||||
|
||||
// aapt resource value: 0x7f0b0018
|
||||
public const int abc_action_bar_home_description = 2131427352;
|
||||
|
||||
37
src/Android/Services/CryptoPrimitiveService.cs
Normal file
37
src/Android/Services/CryptoPrimitiveService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Enums;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using System;
|
||||
|
||||
namespace Bit.Droid.Services
|
||||
{
|
||||
public class CryptoPrimitiveService : ICryptoPrimitiveService
|
||||
{
|
||||
public byte[] Pbkdf2(byte[] password, byte[] salt, CryptoHashAlgorithm algorithm, int iterations)
|
||||
{
|
||||
int keySize = 256;
|
||||
IDigest digest = null;
|
||||
if(algorithm == CryptoHashAlgorithm.Sha256)
|
||||
{
|
||||
keySize = 256;
|
||||
digest = new Sha256Digest();
|
||||
}
|
||||
else if(algorithm == CryptoHashAlgorithm.Sha512)
|
||||
{
|
||||
keySize = 512;
|
||||
digest = new Sha512Digest();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Unsupported PBKDF2 algorithm.");
|
||||
}
|
||||
|
||||
var generator = new Pkcs5S2ParametersGenerator(digest);
|
||||
generator.Init(password, salt, iterations);
|
||||
return ((KeyParameter)generator.GenerateDerivedMacParameters(keySize)).GetKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user