2016-08-02 02:49:04 +02:00
|
|
|
using System;
|
|
|
|
using System.Text;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2016-08-02 03:34:22 +02:00
|
|
|
using Bit.Android.Services;
|
2016-08-02 02:49:04 +02:00
|
|
|
|
|
|
|
namespace Bit.Android.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class KeyDerivationTests
|
|
|
|
{
|
|
|
|
[SetUp]
|
|
|
|
public void Setup() { }
|
|
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
public void Tear() { }
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void MakeKeyFromPasswordBase64()
|
|
|
|
{
|
2016-08-02 03:34:22 +02:00
|
|
|
var service = new BouncyCastleKeyDerivationService();
|
2016-08-02 02:49:04 +02:00
|
|
|
var key = service.DeriveKey(Encoding.UTF8.GetBytes("123456"), Encoding.UTF8.GetBytes("salt"), 5000);
|
|
|
|
Assert.True(key.SequenceEqual(GetKey()));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void HashPasswordBase64()
|
|
|
|
{
|
2016-08-02 03:34:22 +02:00
|
|
|
var service = new BouncyCastleKeyDerivationService();
|
2016-08-02 02:49:04 +02:00
|
|
|
var hash = service.DeriveKey(GetKey(), Encoding.UTF8.GetBytes("123456"), 1);
|
|
|
|
var hashBytes = Convert.FromBase64String("7Bsl4ponrsFu0jGl4yMeLZp5tKqx6g4tLrXhMszIsjQ=");
|
|
|
|
Assert.True(hash.SequenceEqual(hashBytes));
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte[] GetKey()
|
|
|
|
{
|
|
|
|
return Convert.FromBase64String("QpSYI5k0bLQXEygUEHn4wMII3ERatuWDFBszk7JAhbQ=");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|