1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-16 02:17:10 +02:00
bitwarden-mobile/test/App.Test/CryptoServiceTests.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2016-05-02 08:52:09 +02:00
using System;
using Bit.App.Abstractions;
using Bit.App.Services;
using NSubstitute;
using Xunit;
namespace Bit.App.Test
{
public class CryptoServiceTests
{
[Fact]
public void EncryptDecrypt()
{
var value = "hi";
Assert.Equal(EncryptDecryptValue(value), value);
}
[Fact]
public void EncryptDecryptLongValue()
{
var value = "This is a really long value that should encrypt and decrypt just fine too.";
Assert.Equal(EncryptDecryptValue(value), value);
}
private string EncryptDecryptValue(string value)
{
var storageService = Substitute.For<ISecureStorageService>();
var keyService = Substitute.For<IKeyDerivationService>();
storageService.Retrieve("key").Returns(
Convert.FromBase64String("QpSYI5k0bLQXEygUEHn4wMII3ERatuWDFBszk7JAhbQ="));
2016-05-02 08:52:09 +02:00
var service = new CryptoService(storageService, keyService);
2016-05-02 08:52:09 +02:00
var encryptedHi = service.Encrypt(value);
return service.Decrypt(encryptedHi);
}
}
}