mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Created a key derivation interface and initial Pkcs5 implementation
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace mRemoteNG.Security.KeyDerivation
|
||||
{
|
||||
public interface IKeyDerivationFunction
|
||||
{
|
||||
byte[] DeriveKey(string password, byte[] salt);
|
||||
}
|
||||
}
|
||||
31
mRemoteV1/Security/KeyDerivation/Pkcs5S2KeyGenerator.cs
Normal file
31
mRemoteV1/Security/KeyDerivation/Pkcs5S2KeyGenerator.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Generators;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
|
||||
|
||||
namespace mRemoteNG.Security.KeyDerivation
|
||||
{
|
||||
public class Pkcs5S2KeyGenerator : IKeyDerivationFunction
|
||||
{
|
||||
private readonly int _iterations;
|
||||
private readonly int _keyBitSize;
|
||||
|
||||
public Pkcs5S2KeyGenerator(int keyBitSize = 256, int iterations = 1000)
|
||||
{
|
||||
_keyBitSize = keyBitSize;
|
||||
_iterations = iterations;
|
||||
}
|
||||
|
||||
public byte[] DeriveKey(string password, byte[] salt)
|
||||
{
|
||||
var passwordInBytes = PbeParametersGenerator.Pkcs5PasswordToBytes(password.ToCharArray());
|
||||
|
||||
var keyGenerator = new Pkcs5S2ParametersGenerator();
|
||||
keyGenerator.Init(passwordInBytes, salt, _iterations);
|
||||
|
||||
var keyParameter = (KeyParameter) keyGenerator.GenerateDerivedMacParameters(_keyBitSize);
|
||||
var keyBytes = keyParameter.GetKey();
|
||||
return keyBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,6 +192,8 @@
|
||||
<Compile Include="Security\EncryptedSecureString.cs" />
|
||||
<Compile Include="Security\Authentication\IAuthenticator.cs" />
|
||||
<Compile Include="Security\EncryptionException.cs" />
|
||||
<Compile Include="Security\KeyDerivation\IKeyDerivationFunction.cs" />
|
||||
<Compile Include="Security\KeyDerivation\Pkcs5S2KeyGenerator.cs" />
|
||||
<Compile Include="Security\SymmetricEncryption\AeadCryptographyProvider.cs" />
|
||||
<Compile Include="Security\SymmetricEncryption\LegacyRijndaelCryptographyProvider.cs" />
|
||||
<Compile Include="Security\ICryptographyProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user